This repository describes the steps to create an AWS image using Packer. In this example the AMI will be an Ubuntu image with nginx installed and enabled.
See the following documentation How to install Packer
You need access to AWS and have the following credentials
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_SESSION_TOKEN
- Clone the repository to your local machine
git clone https://github.com/munnep/PackerAWSUbuntuNginx.git
- Change your directory
cd PackerAWSUbuntuNginx
- Open the packer file
ubuntunginx.prk.hcland change the region variable to match your preference
variable "region" {
type = string
default = "us-west-2"
}
- Set your AWS environment settings in the terminal with your own credentials
linux/macOS
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_SESSION_TOKEN=
Windows
set AWS_ACCESS_KEY_ID=
set AWS_SECRET_ACCESS_KEY=
set AWS_SESSION_TOKEN=
- Execute the Packer initialization
packer init .
- Execute the Packer build. This will create the AMI in AWS
packer build .
- For the next 5 minutes you'll see output like the following
...
ubuntunginx.amazon-ebs.ubuntunginx: debconf: falling back to frontend: Readline
ubuntunginx.amazon-ebs.ubuntunginx: Setting up nginx-light (1.10.3-0ubuntu0.16.04.5) ...
ubuntunginx.amazon-ebs.ubuntunginx: Setting up nginx (1.10.3-0ubuntu0.16.04.5) ...
ubuntunginx.amazon-ebs.ubuntunginx: Processing triggers for ureadahead (0.100.0-19.1) ...
ubuntunginx.amazon-ebs.ubuntunginx: Processing triggers for systemd (229-4ubuntu21.31) ...
ubuntunginx.amazon-ebs.ubuntunginx: Processing triggers for ufw (0.35-0ubuntu2) ...
==> ubuntunginx.amazon-ebs.ubuntunginx: Synchronizing state of nginx.service with SysV init with /lib/systemd/systemd-sysv-install...
==> ubuntunginx.amazon-ebs.ubuntunginx: Executing /lib/systemd/systemd-sysv-install enable nginx
...
