用boto3创buildElastic Beanstalk Docker环境

我们正在使用boto3dynamic创build弹性beanstalk环境。 我们正在使用与Container beanconfiguration模板一起工作的Single Container Docker Application。 不幸的是,当创build环境时,source_bundle文件没有提取我们的源代码,而Elastic Beanstalk把它称为​​Dockerfile / var / app / current,我通过下载Dockerfile证实了这一点,并能够从中提取我们的源代码。 这很奇怪,也不知道为什么Beanstalk会将我们的源代码包转换为Dockerfile。 我的猜测是boto3与应用程序版本和创build环境的awsebcli不同。

在另一个Beanstalk应用程序中,我们有完全相同的在线应用程序,唯一的区别是它是使用awsebcli而不是boto3创build的

这是我们用来在boto3中创buildElastic Beanstalk应用程序版本的语法

import boto3 client = boto3.client('elasticbeanstalk') source_code = f'archives/xxxxx/xxxxxx.zip' client.create_application_version( ApplicationName=application_name, VersionLabel=commit, Description="foobar", SourceBundle={ 'S3Bucket': 'xxxxxx', 'S3Key': source_code }, AutoCreateApplication=False, Process=True ) 

这就是我们如何使用boto3创build一个beanstalk环境

 import boto3 client = boto3.client('elasticbeanstalk') response = client.create_environment( ApplicationName=application_name, EnvironmentName=name, Description='foobar', Tags=TAGS, VersionLabel=commit, TemplateName='api', ) 

这是我们在弹性beanstalk中的configuration模板

 AWSConfigurationTemplateVersion: 1.1.0.0 EnvironmentConfigurationMetadata: DateCreated: '1488998001000' DateModified: '1501608721804' Description: Configuration created from the EB CLI using "eb config save". EnvironmentTier: Name: WebServer Type: Standard OptionSettings: aws:autoscaling:launchconfiguration: EC2KeyName: xxxx IamInstanceProfile: xxxx InstanceType: t2.small RootVolumeSize: '25' RootVolumeType: standard SecurityGroups: - xxxxx aws:autoscaling:updatepolicy:rollingupdate: MinInstancesInService: 1 RollingUpdateEnabled: true RollingUpdateType: Health aws:elasticbeanstalk:application:environment: URL: xxxxx aws:elasticbeanstalk:command: BatchSize: '30' BatchSizeType: Percentage aws:elasticbeanstalk:environment: EnvironmentType: LoadBalanced ServiceRole: xxxxx aws:elasticbeanstalk:healthreporting:system: SystemType: basic aws:elb:healthcheck: HealthyThreshold: 3 Interval: 60 Target: xxxx Timeout: 10 UnhealthyThreshold: 5 aws:elb:loadbalancer: CrossZone: true SSLCertificateId: xxxxx Platform: PlatformArn: arn:aws:elasticbeanstalk:us-east-1::platform/Docker running on 64bit Amazon Linux/2.3.0