如何解决在 CloudFormation 中配置我的 Amazon ECS 蓝绿部署时遇到的错误?
当我在 AWS CloudFormation 中配置 Amazon Elastic Container Service (Amazon ECS) 蓝绿部署时,出现错误。
解决方法
当您在 CloudFormation 中使用 AWS::CodeDeploy::BlueGreen 钩子时,您可能会收到错误消息。要解决您的错误,请按照相应的解决方案部分进行操作。
解析失败错误
如果您未授予权限或在模板中包含 Weight 属性,则 AWS CodeDeploy 无法解析提供的模板 Hooks 部分。您会收到以下错误消息:
“'CodeDeployBlueGreenHook' of type AWS::CodeDeploy::BlueGreen failed with message: Internal Failure”
当您创建激活蓝绿部署的变更集时,必须将 CloudFormation 服务 AWS Identity and Access Management (IAM) 角色附加到您的 CloudFormation 堆栈。要解决此错误,请向服务角色授予运行堆栈操作的权限。
**注意:**CodeDeploy 创建堆栈后,您无法从堆栈中移除服务角色。
如果您将 DefaultAction 定义为包含 ForwardConfig 属性,但没有在 AWS::ElasticLoadBalancingV2::Listener 资源类型中包含 Weight 属性,则 CodeDeploy 钩子将失效。要解决此错误,请确保在资源类型中包含 Weight 属性。
其他资源错误
当您将启动绿色部署的资源更新以及对其他资源的更新包含在同一堆栈更新中时,会出现以下错误:
“Additional resource diff other than Amazon ECS application related resource update is detected,CodeDeploy can't perform BlueGreen style update properly.Diff resource logical Ids: []”
要解决此错误,请完成以下步骤:
- 执行两个单独的堆栈更新操作。
**注意:**一次堆栈更新必须仅包含启动绿色部署的更新资源(AWS::ECS::TaskDefinition 和 AWS::ECS::TaskSet。第二次堆栈更新必须包括对其他资源的更改。 - 从 CloudFormation 模板中移除 Transform 和 Hooks 部分,然后执行堆栈更新。**注意:**在这种情况下,CloudFormation 不会进行绿色部署。
不支持错误
不支持在 CloudFormation 模板中导入或导出配置。如果您声明 Outputs 或使用 Fn::ImportValue 为定义 Amazon ECS 蓝绿部署的模板从其他堆栈导入值,则会出现以下错误:
“Imports and exports are currently not supported on templates using hooks”
要解决此错误,请勿在模板中使用导入或导出。
CodeDeploy 无法更新使用动态引用从第三方检索其值的参数,或者在绿色部署期间没有 NoEcho 属性定义的参数。使用动态引用时,可能会出现以下错误:
“'CodeDeployBlueGreenHook' of type AWS::CodeDeploy::BlueGreen failed with message: NoEcho parameter Dynamic references is not supported in template when using AWS::CodeDeploy::BlueGreen Hook”
要解决此错误,请勿在模板中使用动态引用。
测试侦听器错误
如果您指定的测试侦听器已经指向绿色目标组,则 CodeDeploy 钩子将失效并出现以下错误:
“'CodeDeployBlueGreenHook' of type AWS::CodeDeploy::BlueGreen failed with message: Replacement target group [ALBTargetGroupGreen] is already serving traffic behind listener [ALBListenerTestTraffic]”
要解决此错误,请确保在上传 CloudFormation 模板时,Production(生产)和 Test Listeners(测试侦听器)字段的值相同。
转换缺失错误
如果您未在更新的 CloudFormation 模板中包含 Transform 部分,则不会调用转换。如果蓝绿资源逻辑 ID 不转换,则会出现以下错误:
“'CodeDeployBlueGreenHook' of type AWS::CodeDeploy::BlueGreen failed with message: The submitted template's primary task definition 'BlueTaskDefinition' was never updated.The template's 'AWS::CodeDeployBlueGreen' Transform might be missing or removed”
要解决此错误,请确保在更新 CloudFormation 堆栈之前在 CloudFormation 模板中包含 Transform 部分。
负载均衡器错误
必须将 TrafficRoutingconfig 类型设置为 AllAtOnce。如果您的模板中包含网络负载均衡器,并将 AWS::CodeDeploy::BlueGreen 钩子和 TrafficRoutingConfig 类型设置为 TimeBasedCanary 或 TimeBasedLinear,则会出现以下错误:
“'CodeDeployBlueGreenHook' of type AWS::CodeDeploy::BlueGreen failed with message: Only AllAtOnce traffic routing config type is supported for network load balancers.”
要解决此错误,请确保将 TrafficRoutingConfig 类型设置为 AllAtOnce。
如果您将负载均衡器 Amazon 资源名称 (ARN) 配置为 Parameter,然后使用 !Ref 在 AWS::ElasticLoadBalancingV2::Listener 中引用 LoadBalancerArn 属性,则可能会出现以下错误:
“Transform AWS::CodeDeployBlueGreen failed with: Failed to transform template.Could not find AWS::ElasticLoadBalancingV2::LoadBalancer LoadBalancerArn”
要解决此错误,请在您的模板中创建负载均衡器资源,并在 LoadBalancerArn 属性中引用 ARN。或者,您可以在 LoadBalancerArn 属性中对负载均衡器 ARN 进行硬编码。
Amazon ECS 服务错误
如果您在 Hooks Applications 属性下添加两个不同的 Amazon ECS 服务目标,它们共享一个应用程序负载均衡器,则可能会出现以下错误:
“'CodeDeployBlueGreenHook' of type AWS::CodeDeploy::BlueGreen failed with message: Handler failed: Applications must have at most one application in AWS::CodeDeploy::BlueGreen Hook”
要解决此错误,请确保您仅将一项 Amazon ECS 服务连接到应用程序负载均衡器。
- 语言
- 中文 (简体)
