Creating a Custom AWS AMI and Launching an EC2 Instance from It
By Łukasz Kallas
- Published on
Sharing
Amazon Machine Images (AMIs) are pre-configured templates that contain the operating system, software, and configurations required to launch an EC2 instance. In this post, we will guide you through the process of creating a custom AMI from an existing EC2 instance and launching a new instance based on this custom AMI.
Steps to Create a Custom AMI
Launch and Configure Your Base EC2 Instance:
- Go to the AWS Management Console.
- Navigate to EC2 and launch an instance using an existing AMI (e.g., Amazon Linux, Ubuntu).
- SSH into the instance and install any necessary software and configure it to your requirements:
sudo yum install nginx -y # Example: Installing Nginx on Amazon Linux sudo systemctl start nginx sudo systemctl enable nginx
Create the Custom AMI:
- Once the instance is configured to your needs, navigate back to the EC2 Dashboard.
- Select the instance you want to use for the custom AMI.
- From the Actions menu, choose Image and templates > Create Image.
- Fill in the details such as the name and description of the AMI, and optionally specify which volumes to include.
- Click Create Image.
Wait for the AMI Creation:
- AWS will take a snapshot of your instance and create the AMI. You can monitor the progress under Images > AMIs in the EC2 Dashboard.
Launch an EC2 Instance from the Custom AMI
Launch an Instance Using the Custom AMI:
- Once your AMI is ready, go to AMIs in the EC2 dashboard.
- Select your custom AMI and click Launch.
- Choose the instance type, configure instance details, security group, and any other settings as needed.
- Review and launch the instance.
Verify the Custom Setup:
- Once the instance is running, SSH into the new instance to verify that all your custom configurations and software are in place:
sudo systemctl status httpd # Verify Nginx or any other custom software
- Once the instance is running, SSH into the new instance to verify that all your custom configurations and software are in place: