我正在尝试使用对流层来制作一个云形态模板。模板的堆栈旨在成为codedeploy的简单示例
我之前有对流层生成ec2,s3,iam和route53生成模板。我之前已经使用GUI AWS Console
进行了codedeploy我遇到错误,我不明白为什么
这是我的对流层计划
from troposphere import Template
from troposphere.codedeploy import Application, DeploymentConfig, DeploymentGroup, MinimumHealthyHosts, S3Location
#1
#CreateApplication with an applicationName
app=Application( 'test123')
#2
#CreateDeploymentConfig
config=DeploymentConfig('config123',
MinimumHealthyHosts=MinimumHealthyHosts( Type='HOST_COUNT', Value=1 )
)
#3
#CreateDeploymentGroup using applicationName as input
#and deploymentConfigName
depgroup=DeploymentGroup("depgroup123",
ApplicationName='test123',
DeploymentConfigName='config123',
ServiceRoleArn='arn:aws:iam::930517348825:role/isCompatibleWithAWSCodeDeploy')
)
t = Template()
t.add_description(
"""
Test of making a code deploy setup from a template
""")
t.add_resource(app)
t.add_resource(config)
t.add_resource(depgroup)
print(t.to_json())
这是它制作的Cloudformation模板
{
"Description": "\nTest of making a code deploy setup from a template\n",
"Resources": {
"config123": {
"Properties": {
"MinimumHealthyHosts": {
"Type": "HOST_COUNT",
"Value": 1
}
},
"Type": "AWS::CodeDeploy::DeploymentConfig"
},
"depgroup123": {
"Properties": {
"ApplicationName": "test123",
"DeploymentConfigName": "config123",
"ServiceRoleArn": "arn:aws:iam::930517348825:role/isCompatibleWithAWSCodeDeploy"
},
"Type": "AWS::CodeDeploy::DeploymentGroup"
},
"test123": {
"Type": "AWS::CodeDeploy::Application"
}
}
}
当我将模板加载到cloudformation GUI时,这会在回滚之前发生
09:08:50 UTC+0000 CREATE_FAILED AWS::CodeDeploy::DeploymentConfig config123 Resource creation cancelled
09:08:48 UTC+0000 CREATE_IN_PROGRESS AWS::CodeDeploy::DeploymentConfig config123
09:08:48 UTC+0000 CREATE_FAILED AWS::CodeDeploy::DeploymentGroup depgroup123 No application found for name: test123
09:08:47 UTC+0000 CREATE_COMPLETE AWS::CodeDeploy::Application test123
我不明白的是,堆栈已经创建了AWS :: CodeDeploy :: Application“test123”,但接下来的消息显示“找不到名称的应用程序:test123”
role / isCompatibleWithAWSCodeDeploy已存在。
我还需要添加其他内容吗?
答案 0 :(得分:1)
只需使用Ref s:
"ApplicationName": {"Ref": "test123"},
"DeploymentConfigName": {"Ref": "config123"},
从我看到的cf模板中,创建的应用程序没有名称。为了使其具有名称,cf模板的相应部分应如下所示:
"test123": {
"Type": "AWS::CodeDeploy::Application",
"Properties" : {
"ApplicationName" : "test123"
}
}
同样适用于配置。配置应具有DeploymentConfigName
属性。
但即使在添加ApplicationName之后,启动也可能失败。因为您的模板不保证在应用程序和deploymentconfig之后创建depgroup。
为了保证正确的创作顺序,您应该使用Ref s:
{
"Description": "\nTest of making a code deploy setup from a template\n",
"Resources": {
"config123": {
"Properties": {
"MinimumHealthyHosts": {
"Type": "HOST_COUNT",
"Value": 1
}
},
"Type": "AWS::CodeDeploy::DeploymentConfig"
},
"depgroup123": {
"Properties": {
"ApplicationName": {"Ref": "test123"},
"DeploymentConfigName": {"Ref": "config123"},
"ServiceRoleArn": "arn:aws:iam::930517348825:role/isCompatibleWithAWSCodeDeploy"
},
"Type": "AWS::CodeDeploy::DeploymentGroup"
},
"test123": {
"Type": "AWS::CodeDeploy::Application"
}
}
}