我正在使用以下代码创建elasticbeanstalk的实例,但是,当我尝试进行部署时,它会抛出No application with name pythonService is found
import cdk = require('@aws-cdk/core');
import ebs = require('@aws-cdk/aws-elasticbeanstalk');
export class DevOpsStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const webAppName: string = 'pythonService';
const webApp = new ebs.CfnApplication(this, webAppName);
const pythonServiceS3BucketName : string = 'my-bucket-name'
const pythonServiceArchiveName : string = 'my-awesome-app.zip'
const webAppVersion = new ebs.CfnApplicationVersion(this, 'pythonServiceVer', {
applicationName: webAppName,
sourceBundle: {
s3Bucket: pythonServiceS3BucketName,
s3Key: pythonServiceArchiveName
}
});
const options: ebs.CfnEnvironment.OptionSettingProperty[] = [{
namespace: 'aws:ec2:vpc',
optionName: 'VPCId',
value: 'a-vpc-id'
}, {
namespace: 'aws:ec2:vpc',
optionName: 'Subnets',
value: 'a-subnet-id'
}];
const webAppEnv = new ebs.CfnEnvironment(this, 'pythonServiceEnv', {
applicationName: webAppName,
solutionStackName: '64bit Amazon Linux 2018.03 v2.9.2 running Python 3.6',
optionSettings: options
});
}
}
我相信这种情况正在发生,因为它试图在创建CfnApplicationVersion
之前部署CfnApplication
。
DevOpsStack: creating CloudFormation changeset...
0/5 | 8:33:48 PM | CREATE_IN_PROGRESS | AWS::ElasticBeanstalk::Application | pythonService
0/5 | 8:33:48 PM | CREATE_IN_PROGRESS | AWS::CDK::Metadata | CDKMetadata
0/5 | 8:33:48 PM | CREATE_IN_PROGRESS | AWS::ElasticBeanstalk::Environment | pythonServiceEnv
0/5 | 8:33:48 PM | CREATE_IN_PROGRESS | AWS::ElasticBeanstalk::ApplicationVersion | pythonServiceVer
0/5 | 8:33:48 PM | CREATE_IN_PROGRESS | AWS::ElasticBeanstalk::Application | pythonService Resource creation Initiated
1/5 | 8:33:48 PM | CREATE_FAILED | AWS::ElasticBeanstalk::ApplicationVersion | pythonServiceVer No Application named 'pythonService' found. (Service: AWSElasticBeanstalk; Status Code: 400; Error Code: InvalidParameterValue; Request ID: cd1a9f2b-a3fc-450a-9c34-fec13132f613)
此外,它生成的cloudformation模板在应用前没有!Ref
:
Resources:
pythonService:
Type: AWS::ElasticBeanstalk::Application
Metadata:
aws:cdk:path: DevOpsStack/pythonService
pythonServiceVer:
Type: AWS::ElasticBeanstalk::ApplicationVersion
Properties:
**ApplicationName: pythonService**
SourceBundle:
S3Bucket: ...
S3Key: ...
答案 0 :(得分:1)
由于CfnApplication和CfnApplicationVersion之间没有引用,因此您必须手动构建依赖关系树。因此,添加CfnApplication作为依赖项,以确保将其部署在CfnApplicationVersion之前:
webAppVersion.addDependsOn(webApp);
答案 1 :(得分:0)
我遇到了类似的问题,发现{{3}}的addDependsOn
建议很有效。
但是,仅添加此修复程序将部署示例应用程序,因为您的环境未引用特定版本。除了dependsOn
修复程序之外,我相信您还需要添加 versionLabel
to your
webAppEnv`:
const webAppEnv = new ebs.CfnEnvironment(this, 'pythonServiceEnv', {
applicationName: webAppName,
solutionStackName: '64bit Amazon Linux 2018.03 v2.9.2 running Python 3.6',
optionSettings: options,
versionLabel webAppVersion.ref
});