[英]How can I catch CloudFormation stack CREATE_COMPLETED event and handle it?
I am creating CloudFormation stack and Lambda that I want to be invoked once stack creation has been completed (stack gained CREATE_COMPLETED status).我正在创建 CloudFormation 堆栈和 Lambda,我想在堆栈创建完成后调用它们(堆栈获得 CREATE_COMPLETED 状态)。 Lambda is not stack resource, but this can be changed to achieve result if needed.
Lambda 不是堆栈资源,但如果需要,可以更改它以实现结果。
Is it possible to catch this event for stack using CloudWatchRule?是否可以使用 CloudWatchRule 为堆栈捕获此事件?
Currently I am able to catch stack resources creation events, but not stack creation itself.目前我能够捕获堆栈资源创建事件,但不能捕获堆栈创建本身。
Similar questions include approaches of subscribing CloudFormationTemplate to SNS topic, however this triggers SNS on each stack resource status change, but not stack itself.类似的问题包括将 CloudFormationTemplate 订阅到 SNS 主题的方法,但是这会在每个堆栈资源状态更改时触发 SNS,而不是堆栈本身。
Given this, Lambda will be invoked on each resource change, which doesnt tell anything about whole template status.鉴于此,Lambda 将在每次资源更改时被调用,它不会告诉任何关于整个模板状态的信息。
This is a duplicate of How to send SNS notification after cloud formation is completed?这是云形成完成后如何发送 SNS 通知的副本? and Is it possible to trigger a lambda on creation from CloudFormation template
是否可以在从 CloudFormation 模板创建时触发 lambda
CloudWatch Rules is not the solution here as Rules are triggered by limited set of services or API calls. CloudWatch 规则不是这里的解决方案,因为规则是由有限的一组服务或 API 调用触发的。 (see the list here https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html )
(请参阅此处的列表https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html )
The solution is to hook your Cloudformation tempate to an SNS topic (see doc here https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html ) and link SNS to a Lambda function.解决方案是将您的 Cloudformation 模板与 SNS 主题挂钩(请参阅此处的文档https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html )并将 SNS 链接到 Lambda 函数。
You will receive message like the below您将收到如下消息
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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.