Full Blog TOC

Full Blog Table Of Content with Keywords Available HERE

Wednesday, September 22, 2021

How to Create a Customized AWS AMI

 

In this post we will review the steps to create a customize AWS AMI.

AWS AMI stands for Amazon Machine Image. It is a snapshot of an EC2 instance volumes, that is used to launch new EC2 instances.


We will start by launching a standard Linux x86 machine. Open the EC2 service in the AWS console, and click on the Launch Instances button.





Select the Amazon Linux 2 AMI, which is a basic empty Linux image.




Next we select the instance type. We will use the t2.micro which has 1 vCPU, and 1G RAM. Then click on the Configure Instance Details button.



Now we select the VPC where the instance is deployed, and click on the Review and Launch button, and then click on the Launch button.




Before the instance is launched we need to select a key pair allowing us to connect to the instance. In this case we will create a new key pair, and down it to be used later. Now we can click on the Launch Instance button.




Now that the instance is launched, we can check its status in the EC2 instance table. We need to wait until the status of the instance is Running.




Let's find the instance public IP by clicking on the EC2 instance.

Notice that in case you do not get a public IP, it means you have selected a subnet for instance which is a private subnet, and hence cannot be accessed from the internet. To create a public subnet, make sure to:

  • Add an Internet Gateway
  • Attach it to the VPC
  • Edit the defaulr Routing Table and add a 2nd rule to redirect all traffic to the internet gateway
  • Edit the subnet and use the Actions button to Enable Auto Assign IPv4 Addresses




To connect to the EC2 instance run the following commands:


chmod 400 my-key.pem
ssh -i my-key.pem ec2-user@44.195.128.228


Now we have a connection to the instance and we can configure it. For example, we can run packages installations, GIT connections, update OS configuration, and more.

In this simple example we will simply create a text file.


echo "Hello World" > /home/ec2-user/indication


Next we stop the EC2 instance, and create an image from it.





We can use the Images menu to track the image creation process.





Once the images is ready we can use it for a new EC2 instance creation.




That's all for this time!



No comments:

Post a Comment