Effortless Updates: How to Automatically Trigger Custom Resources in CloudFormation
Discover how to enhance your AWS CloudFormation deployments by automatically invoking custom resources whenever Lambda function code is updated. This article explores a practical solution using dynamic parameters to streamline workflows and improve automation, ensuring your cloud infrastructure remains agile and up-to-date
LambdaExecutionTimestamp
), developers can ensure that any update to the Lambda function will trigger the execution of the custom resource. Here’s how this can be implemented:1
2
3
LambdaExecutionTimestamp:
Type: String
Default: '201906240927' # Example timestamp; this should be updated with each deployment.
AWS::CloudFormation::CustomResource
type. By referencing the timestamp parameter in the properties of the custom resource, any change to its value will prompt CloudFormation to re-execute the custom resource.1
2
3
4
5
6
7
ExecuteLambda:
Type: AWS::CloudFormation::CustomResource
Properties:
ServiceToken: !GetAtt
- LambdaFunction
- Arn
Timestamp: !Ref LambdaExecutionTimestamp
LambdaExecutionTimestamp
parameter with each deployment. This can be done manually or automated through CI/CD pipelines, ensuring that it always reflects a new value. When using CodePipeline, customers can generate TimeStamp at the time of the build and pass it as parameter to the CloudFormation stack.- Consistent Invocation of Custom Resources: By utilizing a dynamic timestamp parameter, custom resources are invoked every time there is an update to the Lambda function code. This eliminates the need for manual checks and interventions, streamlining the deployment process.
- Enhanced Automation: This approach minimizes potential errors associated with manual updates and ensures that all resources remain current and properly configured.
- Improved Deployment Efficiency: The overall deployment process becomes more efficient, allowing teams to push updates confidently. They can be assured that all resources will reflect the latest changes without requiring additional steps.