Last active
October 3, 2022 19:24
-
-
Save daaru00/d5443e5de9b25fd7ee637e6d6a22d137 to your computer and use it in GitHub Desktop.
Use EventBridge events to execute code when the CloudFormation stack itself is created
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: "2010-09-09" | |
Transform: "AWS::Serverless-2016-10-31" | |
Resources: | |
LogGroup: | |
Type: AWS::Logs::LogGroup | |
Properties: | |
LogGroupName: !Sub /aws/lambda/${StackCreatedFunction} | |
RetentionInDays: 7 | |
StackCreatedFunction: | |
Type: AWS::Serverless::Function | |
Properties: | |
FunctionName: !Sub "${AWS::StackName}-created" | |
Handler: index.handler | |
Runtime: nodejs16.x | |
InlineCode: !Sub |- | |
exports.handler = async (event) => { | |
console.log(`Stack ${AWS::StackName} created!`) | |
} | |
Events: | |
StackEvent: | |
Type: EventBridgeRule | |
Properties: | |
EventBusName: default | |
Pattern: | |
source: | |
- aws.cloudformation | |
detail-type: | |
- CloudFormation Stack Status Change | |
detail: | |
stack-id: | |
- !Ref AWS::StackId | |
status-details: | |
status: | |
- CREATE_COMPLETE | |
Outputs: | |
LogGroupName: | |
Description: "The name of the lambda function log group" | |
Value: !Ref LogGroup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment