Create a Custom AMI in AWS

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

The AMIs provided by AWS contain little more than just the operating system. So to run a PHP web application, for example, you would need to install Apache and PHP. This can be done automatically using User Data, or with an automation tool like Chef or Puppet. Doing it that way extends the wait time to instance “readiness.”

Many applications, such as those in an autoscaling environnemt, need instances ready to use immediately. By creating custom AMIs we can lauch pre-configured instances and skip the wait.

Note: For Windows PuTTY ssh connections to EC2 instances, see: or

For information on using the Cloud Playground, see:

** Please reference the updated commands provided in the Objectives section.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Launch a Configuration Instance

Launch an instance from a Base AWS Linux AMI:

  • Login to the Management Console
  • Launch EC2 instance using the AWS Linux AMI:
    • t2.micro
    • Public IP
    • Create a Security Group with SSH (TCP 22) an HTTP (TCP 80) access
    • Download a Key Pair
Install Apache and PHP

SSH to the instance and execute the following commands to install Apache and PHP:
(Windows users see: for using PuTTY for SSH)

  • sudo yum update -y
  • sudo yum install -y httpd php
  • sudo systemctl start httpd
  • sudo systemctl enable httpd

Create a PHP page with the following commands:

  • sudo usermod -a -G apache ec2-user
  • sudo chown -R ec2-user:apache /var/www
  • echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

To display the PHP Info page, open a web browser to: [Your EC2 Instance’s Public IP]/phpinfo.php

Create a Custom AMI

In the EC2 Management Console, create an image from the config instance:

  • Select the instance in the console
  • Under the Actions menu, choose Create Image:
    • Name the Image
  • Launch an instance from the new Image by going under "MyAMI’s"
  • Configure the new instance’s details as before.
  • Verify the PHP page displays in the browser as before (you can use your existing SG that you created).

Additional Resources

Please go ahead and log in to the live environment with the cloud_user credentials provided. Make sure you are using us-east-1 as your region throughout the lab.

To connect to the instance we will use the Mac Terminal app. If you are using Windows, you will need an SSH client such as Putty.

When launching an instance, please use the Amazon Linux AMI

If you use the Instant Terminal, allow all IPs when configuring your Security Group for SSH.

Please use sudo yum install httpd php when installing apache and php

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?