AWS EC2 AMI Hands-On | A Step-by-Step Guide
A step-by-step instructions on EC2 Instance Storage: Amazon Machine Images (AMI)
Table of contents
Launch EC2 Instance
- To Launch the EC2 instance follow steps from Step-by-step guideline to launch EC2 Instance. However, ensure to update Step 6. Add User Data Script bash script with below.
#!/bin/bash
# Update the package repository and install Apache
yum update -y
yum install -y httpd
# Start the Apache service
service httpd start
# Enable Apache to start on system boot
systemctl enable httpd
We Launched a new EC2 instance
-
You can Go to PublicIP to test your running state of EC2 server
Create an Image
In the EC2 dashboard, locate and click on "Instance" in the left-hand sidebar under the "Instances" section.
Select your running Instance from Instances Interface's list
Go to "Actions"->"Image and Templates"->"Create Image"
Specify the name for the new image and then click the “Create Image” button.
You'll be redirected to Instances, with a notification that your image is created.
Launch Instance from AMI
In the EC2 dashboard, locate and click on "Instance" in the left-hand sidebar under the "Instances" section.
In the EC2 dashboard, click on the "Launch Instance" button
Select an "my AMIs" tab and select your AMI from the dropdown.
Select the instance type based on your workload requirements (e.g., t2.micro for a basic test) and key pair login from dropdown.
selecting an existing security group to control traffic to your instance.
Go to "Advance Settings" and all the way to the bottom paste user Data.
COPY
#!/bin/bash # Create a simple HTML page to verify Apache installation echo "<html><head><title>Test Page</title></head><body><h1>Apache is running!</h1></body></html>" > /var/www/html/index.html
This Time we are just Creating a web page, as rest of the boot script is already available in our AMI
Click "Launch" to initiate the instance creation process.
Once your instance is launched, you can monitor its status from the EC2 dashboard.
To access your instance, click on the "Instances" link in the navigation pane, then select your instance from the list.
From here, you can view details about your instance, including its public IP address and status.
To test the running instance go to http://<IP_address> or click of public IP above, just ensure it is http:// and not https://