gpt4 book ai didi

amazon-web-services - 如何捕获 CloudFormation 堆栈 CREATE_COMPLETED 事件并处理它?

转载 作者:行者123 更新时间:2023-12-03 07:14:41 25 4
gpt4 key购买 nike

我正在创建 CloudFormation 堆栈和 Lambda,希望在堆栈创建完成后调用它们(堆栈获得 CREATE_COMPLETED 状态)。 Lambda 不是堆栈资源,但​​如果需要,可以更改它以获得结果。

是否可以使用 CloudWatchRule 捕获此事件以进行堆栈?

目前我能够捕获堆栈资源创建事件,但不能捕获堆栈创建本身。

类似的问题包括将 CloudFormationTemplate 订阅 SNS 主题的方法,但这会在每个堆栈资源状态更改上触发 SNS,但不会触发堆栈本身。

鉴于此,每次资源更改时都会调用 Lambda,这不会透露有关整个模板状态的任何信息。

最佳答案

这是 How to send SNS notification after cloud formation is completed? 的重复项和 Is it possible to trigger a lambda on creation from CloudFormation template

CloudWatch 规则不是此处的解决方案,因为规则是由有限的服务或 API 调用集触发的。 (请参阅此处的列表 https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html )

解决方案是将您的 Cloudformation 模板 Hook 到 SNS 主题(请参阅此处的文档 https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html )并将 SNS 链接到 Lambda 函数。

您将收到如下消息

StackId='arn:aws:cloudformation:eu-west-1:99999999999:stack/test/b08a8460-368c-11e9-be1f-025fe09a8a16'
Timestamp='2019-02-22T10:30:41.127Z'
EventId='e710f3c0-368c-11e9-b22d-06366d428b7a'
LogicalResourceId='test'
Namespace='486652066693'
PhysicalResourceId='arn:aws:cloudformation:eu-west-1:486652066693:stack/test/b08a8460-368c-11e9-be1f-025fe09a8a16'
PrincipalId='AID....6SK'
ResourceProperties='null'
ResourceStatus='CREATE_COMPLETE'
ResourceStatusReason=''
ResourceType='AWS::CloudFormation::Stack'
StackName='test'
ClientRequestToken='Console-CreateStack-c305c793-9a83-b175-bd26-f251aee30adc'

关于amazon-web-services - 如何捕获 CloudFormation 堆栈 CREATE_COMPLETED 事件并处理它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54823210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com