The Lambda function finishes by adding tags to the SSM parameter. If it’s available, it extracts the AMI ID from the SNS message payload and updates the SSM parameter specified.The ‘ssm_parameter_name’ variable specifies the SSM parameter path where the AMI ID should be stored and updated. It first checks the SNS message payload to determine if the image is available.
Automate OS Image Build Pipelines with EC2 Image Builder provides a tutorial on how to create an image pipeline with the EC2 Image Builder console.An existing Amazon EC2 Image Builder pipeline.To get started with this solution, the following is required: If the image state is available, it retrieves the AMI ID from the message payload and updates the SSM parameter.ĮC2 Image builder architecture diagram Prerequisites The Lambda function first checks the message payload to see if the image status is available. The Lambda function receives the message payload as an input parameter. When a Lambda function subscribes to an SNS topic, it is invoked with the payload of the published messages. This results in the Lambda function being invoked at the completion of the Image Builder pipeline. Once deployed, the SNS topic must be configured in an existing Image Builder pipeline. The Lambda function and the SNS topic are deployed using AWS SAM CLI. This solution uses a Lambda function written in Python that subscribes to an Amazon Simple Notification Service (SNS) topic.
With the SSM parameter integration, your code remains untouched and a CloudFormation stack update operation automatically fetches the latest Parameter Store value. Then to update these, you would manually change them in each of your templates. Normally, you might map AMI IDs to specific instance types and Regions. Consider the use case of updating Amazon Machine Image (AMI) IDs for the EC2 instances in your CloudFormation templates. Users can reference the SSM parameters in automation scripts and AWS CloudFormation templates providing access to the latest AMI ID for your EC2 infrastructure. Standard SSM parameters are available at no additional charge. In this case, the Lambda function is invoked upon the completion of the image builder pipeline. You are charged based on the number of requests for your functions and the time it takes for your code to run. With Lambda, you pay only for what you use. It tracks and updates the latest Amazon Machine Image (AMI) IDs every time an Image Builder pipeline is run. In this blog post, I walk through a solution that uses AWS Lambda and AWS Systems Manager (SSM) Parameter Store. Customers have told us that they manage multiple server images and are looking for ways to track the latest server images created by the pipelines. Image Builder reduces the effort of keeping images up-to-date and secure by providing a graphical interface, built-in automation, and AWS-provided security settings. The images created by EC2 Image Builder can be used with Amazon Elastic Compute Cloud (EC2) and on-premises.
The Amazon EC2 Image Builder service helps users to build and maintain server images.
This post courtesy of Anoop Rachamadugu, Cloud Architect at AWS