DEV Community

GargeeBhatnagar for AWS Community Builders

Posted on

How to Create a Custom AMI with Image Pipeline and Automate its Creation Using EC2 Image Builder

“Challenges faced to find the solution of how to create a custom ami with image pipeline and automate its creation using ec2 image builder”. I have checked various documents on how to create a custom ami with required OS and packages and also able to automate the process of creating the custom image. I have found a way to do it using the EC2 image builder service of AWS. EC2 image builder is easy to use and able to create a custom AMI with image pipeline and also it is free of charge. We can also do custom VPC and other configuration while creating AMI in the image pipeline.

EC2 Image Builder is a fully managed AWS service that makes it easier to automate the creation, management, and deployment of customized, secure and up-to-date server images that are pre-installed and pre-configured with software and settings to meet specific IT standards.

EC2 Image Builder simplifies the building, testing and deployment of Virtual Machine and container images for use on AWS or on-premises. Keeping Virtual Machine and container images up-to-date can be time consuming, resource intensive and error-prone. Currently, customers either manually update and snapshot VMs or have teams that build automation scripts to maintain images.

Image Builder significantly reduces the effort of keeping images up-to-date and secure by providing a simple graphical interface, built-in automation, and AWS-provided security settings. With Image Builder, there are no manual steps for updating an image nor do you have to build your own automation pipeline. Image Builder is offered at no cost, other than the cost of the underlying AWS resources used to create, store and share the images.

In this post, you will get to know how to create a custom ami with image pipeline and automate its creation using ec2 image builder. Here I have used an EC2 image builder and IAM role with required permissions policy.

Architecture Overview

Image description
The architecture diagram shows the overall deployment architecture with data flow, ec2 image builder and ec2 console with AMI.

Solution overview

The blog post consists of the following phases:

  1. Create Image Pipeline with required IAM permissions
  2. Run the Image Pipeline and Get the AMI and Snapshot Available
  3. Check the Log Events in Cloudwatch

Phase 1: Create Image Pipeline with required IAM permissions

  1. Open the ec2 image builder console, click on create image pipeline. Give the pipeline name, choose the build schedule, create an image recipe with the image type and its version. Select OS, instance configuration and working directory. Create a build component with component details and content. Also select the test to verify the output AMI and can also set the storage volume as per requirement. Define infrastructure configuration and distribution settings. And then create an image pipeline. Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description

Phase 2: Run the Image Pipeline and Get the AMI and Snapshot Available

  1. We can change the infrastructure and scheduler builder settings as per requirement. Once the image pipeline is ready, we can run the pipeline using the run pipeline option. In the Image pipeline, the AMI creation goes through various status as pending, building, testing and distributing state. Once the process completes, we can go to the EC2 console and check the AMI and snapshots created. We can also disable and enable the pipeline. Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description

Phase 3: Check the Log Events in Cloudwatch

  1. Open the cloudwatch console and check the log events in log groups. Image description Image description Image description Image description

Clean-up

Delete EC2 Image Builder, EC2 AMI and Snapshot, IAM Role, Cloudwatch Log groups.

Pricing

I review the pricing and estimated cost of this example.

No cost for EC2 Image Builder as it's free of charge.

Cost of Cloudwatch = $0.0

Total Cost = $0.0

Summary

In this post, I showed “how to create a custom ami with image pipeline and automate its creation using ec2 image builder”.

For more details on EC2 Image Builder, Checkout Get started EC2 Image Builder, open the EC2 Image Builder console. To learn more, read the EC2 Image Builder documentation.

Thanks for reading!

Connect with me: Linkedin
Image description

Top comments (0)