In this tutorial you will build a t2.micro Amazon EC2 AMI.[1]
The following section contains a complete Packer template that can be used to build an AWS Ubuntu AMI in the us-west-2
region.
Create a file named aws-ubuntu.pkr.hcl
and add the following code:
1 | packer { |
Authenticate to AWS
Before you can build the AMI, you need to provide your AWS credentials to Packer as environment variables.
These credentials should have permissions to create, modify and delete EC2 instances.
For the full list IAM permissions required to run the amazon-ebs builder perform a google search.
Add your AWS credentials as two environment variables, AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
.
You may need to also export your AWS_SESSION_TOKEN
and AWS_SESSION_EXPIRATION
as environment variables.
LINUX
1 | $ export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY |
WINDWS
1 | > set AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY |
Build
Run through the following Pack commands to build the image(s):
1 | Initialize your Packer configuration. |
Verify
Visit the AWS AMI Wizard page in the same region to verify that Packer successfully built your AMI.