AWS EC2 AMI Hands-On | A Step-by-Step Guide

Divya MahajanDivya Mahajan
2 min read

Launch EC2 Instance

  1. 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
  1. We Launched a new EC2 instance

  2. You can Go to PublicIP to test your running state of EC2 server


Create an Image

  1. In the EC2 dashboard, locate and click on "Instance" in the left-hand sidebar under the "Instances" section.

  2. Select your running Instance from Instances Interface's list

  3. Go to "Actions"->"Image and Templates"->"Create Image"

  4. Specify the name for the new image and then click the “Create Image” button.

  5. You'll be redirected to Instances, with a notification that your image is created.


Launch Instance from AMI

  1. In the EC2 dashboard, locate and click on "Instance" in the left-hand sidebar under the "Instances" section.

  2. In the EC2 dashboard, click on the "Launch Instance" button

  3. Select an "my AMIs" tab and select your AMI from the dropdown.

  4. Select the instance type based on your workload requirements (e.g., t2.micro for a basic test) and key pair login from dropdown.

  5. selecting an existing security group to control traffic to your instance.

  6. 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

  7. Click "Launch" to initiate the instance creation process.

  8. 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://

0
Subscribe to my newsletter

Read articles from Divya Mahajan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Divya Mahajan
Divya Mahajan

Experienced Technical developer with 6+ years' global collaboration. Proficient in Python, Go, React, Next.js, Django, various databases, Cloud & DevOps (AWS EC2, Docker, Kubernetes), and Big Data tools. Skilled in data structures and algorithm, API development, and end-to-end software engineering. Excels in back-end development, front-end design, Root Cause Analysis, and product management to deliver superior user experiences. Holds a master’s degree in computer engineering.