- Create AWS access keys
- Create AWS EC2 Key Pair
- (Optional) Set AWS Multi-factor authentication (MFA) credentials
🤔 When creating an AWS AMI, an AWS access key is needed by Packer to access the account.
This information is usually kept in ~/.aws/credentials
and is accessed by the Packer amazon-ebs
builder.
-
Method #1: Use the
aws
command line interface to create~/.aws/credentials
. Supply the information when prompted. Example:$ aws configure AWS Access Key ID: AWS Secret Access Key: Default region name [us-east-1]: Default output format [json]:
-
Method #2: ✏️ Manually create a
~/.aws/credentials
file. Example:mkdir ~/.aws cat <<EOT > ~/.aws/credentials [default] aws_access_key_id = AAAAAAAAAAAAAAAAAAAA aws_secret_access_key = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx EOT chmod 770 ~/.aws chmod 750 ~/.aws/credentials
-
References:
- Packer using AWS authentication
🤔 When creating an AWS AMI, a EC2 key pair is required by Packer to access the EC2 instance that is used to create the AMI. With access, Packer is able to run provisioners such as Ansible on the EC2 instance
-
Create EC2 key pair
-
Add key pair to custom-var.json
{
"aws_ssh_keypair_name": "packer-key",
"aws_ssh_private_key_file": "~/packer-key.pem",
}
🤔 If the AWS account is setup with multi-factor authentication, a new set of access key id, key and session token has to generated ephemerally for packer to build the AMI.
Do follow the AWS MFA guide to setup the credentials required to build AMI.