- Create a new Packer template file and start by defining an amazon-ebs builder in the builders section. Note that the entire file, 13-01-Hashi.json, is available in the GitHub repository of this book https://github.com/PacktPublishing/AWS-SysOps-Cookbook-Second-Edition:
"builders": [
{
"type": "amazon-ebs",
"instance_type": "t2.micro",
"region": "us-east-1",
"source_ami": "ami-9be6f38c",
"ssh_username": "ec2-user",
"ami_name": "aws-linux-apache {{timestamp}}"
}
],
The entire template file must be a valid JSON object. Remember to enclose the sections in curly braces: { ... }.
- Create a provisioners section and include the following snippet to install and activate Apache:
"provisioners": [
{
"type": "shell",
"inline": [
"sudo yum install -y httpd",
"sudo chkconfig httpd on"
]
}
]
- Save the file with a specific name, such as 13-01-Hashi.json.
- Validate the configuration file you've created with the following packer validate command:
packer validate 13-01-Hashi.json
- When valid, build the AMI with the following command:
packer build13-01-Hashi.json
- Wait until the process is complete. While it is running, you will see an output similar to the following:
Packer build
- Take note of the AMI ID returned by Packer so that you can use it when launching instances in the future:
Packer build finished
Now, you can log in to your AWS account and go to the EC2 dashboard to verify the creation of the AMI in your default region.