【发布时间】:2019-02-21 07:43:16
【问题描述】:
在 AWS Cloudformation 中有无法直接更新的特殊资源。它们将被替换为 aws cloudformation update-stack 命令。只要您不想在更新后保留这些资源,此方法就可以正常工作。
在我的示例中,我想保留 AWS::AutoScaling::LaunchConfiguration 资源的所有更新版本,以便手动切换 AutoScalingGroup 中的 LaunchConfigurations(用于测试目的或紧急回滚)。我需要这样做,因为 Web 界面用户无法使用 Cloudformation,他们也无权这样做。
所以我创建了一个模板,该模板通过设置包含当前日期/时间的自定义 LaunchConfigurationName 创建/更新 LaunchConfiguration 资源。
这很好用,但是:
在UPDATE_COMPLETE_CLEANUP_IN_PROGRESS 状态之后,旧版本的AWS::AutoScaling::LaunchConfiguration 资源总是被删除。为了避免这种情况,我尝试设置一个 set-stack-policy:
{
"Statement" : [
{
"Effect" : "Allow",
"Action" : "Update:*",
"Principal": "*",
"Resource" : "*"
},
{
"Effect" : "Deny",
"Action" : "Update:Delete",
"Principal" : "*",
"Resource" : "*",
"Condition" : {
"StringEquals" : {
"ResourceType" : ["AWS::AutoScaling::LaunchConfiguration"]
}
}
}
]
}
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/protect-stack-resources.html
Update:Delete
Specifies update actions during which resources are removed.
Updates that completely remove resources from a stack template require this action.
结果:更新 AutoScalingGroup(UPDATE_COMPLETE_CLEANUP_IN_PROGRESS 状态)后,资源仍会被删除。
您知道如何保留旧版本吗?
【问题讨论】:
标签: amazon-web-services amazon-cloudformation autoscaling