Reputation: 443
I am creating CloudFormation stack and Lambda that I want to be invoked once stack creation has been completed (stack gained CREATE_COMPLETED status). Lambda is not stack resource, but this can be changed to achieve result if needed.
Is it possible to catch this event for stack using 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.
Given this, Lambda will be invoked on each resource change, which doesnt tell anything about whole template status.
Upvotes: 2
Views: 1775
Reputation: 14905
This is a duplicate of How to send SNS notification after cloud formation is completed? and Is it possible to trigger a lambda on creation from CloudFormation template
CloudWatch Rules is not the solution here as Rules are triggered by limited set of services or API calls. (see the list here 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.
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'
Upvotes: 2