How to do it...

  1. 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: { ... }.
  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 13-01-Hashi.json.
  1. Validate the configuration file you've created with the following packer validate command:
      packer validate 13-01-Hashi.json
  1. When valid, build the AMI with the following command:
      packer build13-01-Hashi.json
  1. Wait until the process is complete. While it is running, you will see an output similar to the following:

Packer build
  1. 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. 

..................Content has been hidden....................

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