Building an Amazon EBS-Based Packer Image

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Packer allows us to use JSON or HCL code to describe and generate machine images, such as AWS AMIs. In this lab, we’ll explore using Packer alongside AWS, from initial key creation to final Packer build as we write a Packer template from scratch using the `amazon-ebs` builder and a selection of provisioners.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create Access Key and Secret Key, Discover Subnet
  1. Navigate to IAM > Users, and click on our cloud_user.
  2. Click the Security credentials tab, and select Create access key. Make a note of the Access key ID and Secret access key.
  3. Navigate to VPC > Subnets, and copy the subnet ID.
Write Template Based on Provided Instructions
  1. Change to the packer/booksite directory.
  2. Create a packer.json file.
  3. Write the template based on the details in the instructions.
Test the Build

Validate and run the build.

Additional Resources

As the DevOps Engineer in charge of all Packer builds, you have been tasked by the frontend team to create an image that can deploy the landing page from the website. The website files have been provided to you, and you've already decided to deploy on an Amazon Linux 2 AMI (amzn2-ami-hvm-2.0.<TIMESTAMP>-gp2) and have created a script.

The resulting AMI should have a well-defined name and a simple description. The following tags should also be added:

  • Builder=Packer
  • Role=Web
  • Team=Frontend

Additionally, the company is currently auditing storage costs and has requested unused AMIs not be stored. Ensure to deregister and delete any snapshots that use the same name as the resulting AMI.

Note that a default VPC and subnet is not provided, and any subnet information will have to be located in the AWS console. Access and secret keys will also need to be created. A security group with the tag name packer has been provided.

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?