How to do it...

  1. Create a new Packer template file, and start by defining an amazon-ebs builder in the builders section:
      "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: { ... }.
  1. 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"
]
}
]
  1. Save the file with a specific name, such as 04-creating-machine-images.json.
  1. Validate the configuration file you've created with the following packer validate command:
      packer validate 04-creating-machine-images.json
  1. When valid, build the AMI with the following command:
      packer build 04-creating-machine-images.json
  1. Wait until the process is complete. While it is running, you will see an output similar to the following:
  1. Take note of the AMI ID returned by Packer so that you can use it when launching instances in the future:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset