![]() |
EC2 builder is a tool provided by AWS cloud providers to create, customize, manage, and distribute EC2 images(AMIs). This is like a one-stop shop for everything you want to do using AWS AMIs. In this article, we will see how to create an EC2 Build pipeline and how to create an AMI using it. AMI stands for Amazon Machin Image. According to AWS’s official documentation, An Amazon Machine Image (AMI) is an image provided by AWS that provides the information required to launch an instance. You must specify an AMI when you launch an instance. You can launch multiple instances from a single AMI when you require multiple instances with the same configuration. You can use different AMIs to launch instances when you require instances with different configurations. An AMI contains all the information necessary to launch an instance, such as:
An AMI helps with the following:
So in simple words, let’s say we have an EC2 server on AWS(which you have created manually or using AWS public image) and you can take a snapshot of its state like OS, hardware (storage) type as listed above. Store this snapshot and then use this to turn up more servers that are exactly like your first server. You have an additional option to edit this configuration for the new servers during their creation. Amazon provides several types of AMIs, including:
AMIs save a lot of time the user spends manually configuring all these specifications for each server. 2. Prerequisite:We assume that you already have an AWS account. If not, go ahead and create an account from here: https://aws.amazon.com/console/
3. Step-By-Step Guide to Use EC2 Image BuilderStep 1: Log in to the AWS console. Step 2: Navigate to the EC2 home page. Then you will be able to see the available services under EC2, under the Images section in the side navigation bar, you will be able to see the text AMIs as shown below. Click on it. ![]() Step 3: You will be redirected to the view where the available images are displayed by default and then on the top you will see an option called EC2 Image Builder, you can refer the below image for reference ![]()
Now you will be re-directed to the EC2 Image Builder home screen. This screen provides lot of information about how EC2 Image builder pipeline works on an overall level, some usecases that we might be interested. Please feel free to give it a read before clicking on Create image pipeline. To proceed further we need an IAM(Identity and Access Management) role with access to EC2 and Image building services. You can duplicate the tab or open a new tab, navigate to AWS console and follow along. Step 4: Create an IAM Role You can type IAM in the top left search bar available in the AWS console. Click on IAM and then you will be re-directed to IAM dashboard. Then you need to click on Roles in the left side navigation bar under Access Management. Then you will see Roles Dashboard as shown below: ![]() Roles home page Click on Create Role, then you will see the below view. ![]() Role creation is done in 3 stages as shown
![]() Click on Next and enter the remaining details as shown in the below image ![]() 3. click on Create Role, then GFGIAMForEC2ImageBuilder role is created. ![]() Step 5: Now we resume to EC2 Image Builder screen. We will chose the public AMI provided by AWS market place in our EC2 Builder pipeline flow. As discussed in Step 3, when you click on Create image pipeline, you will see the below view, where you can enter pipeline line and configure how you want to run the pipeline. ![]() Enter the pipeline name as GFGImagePipeline, you can paste the same in the description too, if you scroll down a little you will see Build schedule. Select Manual for now as we are going to run it manually. We can choose to run it at regular intervals, or run at some point in the future once. But for now, lets go with Manual. Click on Next. Now, we need to choose a recipe. Select Create new recipe. One good thing about cloud providers like this is we can get basic understanding of each service during their creation itself. If you observe in this view, you see the definition for the recipe which is “An image recipe is a document that defines the components to be applied to the base images to create the desired configuration for the output image”. So pay close attention to the views when you are on the console. Select Image Type as AMI, Amazon Machine Image. You can experiment with Docker Image too, but that’s topic for some other day. Now, if you scroll down a little you will see a section called General, under this you need to type your recipe name, enter GFGImageRecipe and version as 1.0.0. Scoll down a little bit further, under Base Image choose select managed images, and select Amzon Linux 2 x86 as the operating system. ![]() Now if you scroll down further you will see the Components section, here you can select any additional tools or services you want, refer the above image for details. All the selected components will be visible at one place if you scroll down more.
I have selected the following two. ![]() I selected the following for test component to test the image boot status. This step is completely optional but its good to have this checked. ![]() Leave the other values of storage as it is and click on Next, followed by Default workflows also, click Next. ![]() Step 6: Now we need to configure the infrastructure, means VPC(Virtual Private Cloud). Enter the name of the VPC as GFGConfigVPC and select the IAM role we created in step 4 here. ![]() Now select the instant type as t2.micro and then click Next. The next two steps are also optional, then click on Create pipeline. It might take a while, but once the pipeline is created, you can see it in the EC2 Image Builder > Image pipelines. 4. Run Pipeline![]() You can select the pipeline that we just created and click on Actions, choose Run Pipeline. It might take more than 15 mins for this action’s completion. You can click on the pipeline name and get more details like the status of the pipeline, you will see the status as building or pending initially. If you navigate to EC2 dashboard, you will be able to see an EC2 instance that got created by the image pipeline we just created above. ![]() After roughly around 15 mins, the pipeline state changed to testing, at this point you will be able to see the below two instances, one for the actual image which gets terminated and the other one for testing. ![]() Now after roughly about 10 mins, the pipeline status changed to distributing, and the Test Instance status will be changed to Terminated. Now the final part where we check if our image that we created through pipeline is available or not. Navigate to EC2 home page and click on Launch Instances, you will see the below option once you click on My AMIs. ![]() if you are able to see this, Congratulations! you have successfully created an AMI using EC2 Image Builder. The same recipe can be used to create more pipelines, and this image can be used to create as many EC2 instances as required, rather than we manually creat images, we can run this pipeline and a new image will be created for us whenever needed, we can edit this pipeline as and when we want. 6. PricingUsing EC2 Image Builder to create custom AMIs is free of charge, however the following are not.
visit the official website for more up to date and accurate details as these values tend to change over time 7. ConclusionEC2 Image Builder is an amazing tool, even though it is free to use, but still it incurs costs for other services that are being used as part of the pipeline. So, analyse your use cases and plan your pipeline stages accordingly. EC2 Image Builder – FAQsCan I schedule image creation tasks?
How does EC2 Image Builder help with security and compliance?
Can I use EC2 Image Builder in a multi-account environment?
What should I do if my image build fails?
Can I customize the build components used in my image?
|
Reffered: https://www.geeksforgeeks.org
Amazon Web Services |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |