Yes, it is possible. Here are a few options:
-
Manually create an SNS Topic. Add an
AWS::SNS::Subscription
to your stack with the lambda function as theEndpoint
and the SNS topic as theTopicArn
. On stack creation/update, configure Stack Event Notifications to be sent to this SNS topic.- (See Setting AWS CloudFormation Stack Options for documentation on how to do this when using the AWS Console to create your stack, or use the equivalent option like
--notification-arns
if creating/updating your stack using the AWS CLI or other AWS SDK.)
- (See Setting AWS CloudFormation Stack Options for documentation on how to do this when using the AWS Console to create your stack, or use the equivalent option like
-
Add a Custom Resource referencing a Lambda function to be called on creation.
- If you need the Lambda function to be called after some specific Resource is created, add a
DependsOn
attribute on the Custom Resource referencing the Resource you want to make sure is created first before the function is called. - In order for the Custom Resource to create successfully (and not cause a failure/rollback in your stack), you will need to adapt your Lambda function to support the CloudFormation request/response format (see Custom Resource Reference).
- This option will call the Lambda function while the stack status is still
CREATE_IN_PROGRESS
, because the Custom Resource is part of the stack itself. - The Lambda function will also be called again when the stack (and associated Custom Resource) is deleted. This will need to be handled by your Lambda function correctly, or your stack could get stuck in the
DELETE_FAILED
state.
- If you need the Lambda function to be called after some specific Resource is created, add a
-
Add the Lambda function reference to a Stack Output, then write a simple script that performs the stack creation and then manually invokes the Lambda function afterwards.