Skip to content

Instantly share code, notes, and snippets.

@arhea
Last active January 20, 2017 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arhea/574b2d26a23b0d36a54a7ecdc9ede12c to your computer and use it in GitHub Desktop.
Save arhea/574b2d26a23b0d36a54a7ecdc9ede12c to your computer and use it in GitHub Desktop.
Docker AMI Build with Packer
#!/bin/bash
set -ex
echo "Gathering AWS Credentials..."
AWS_ACCESS_KEY=$(aws configure get aws_access_key_id --profile=$1)
AWS_SECRET_KEY=$(aws configure get aws_secret_access_key --profile=$1)
AWS_REGION=$(aws configure get region --profile=$1)
AWS_ACCOUNT_ID=$(aws ec2 describe-security-groups --group-names 'Default' --query 'SecurityGroups[0].OwnerId' --output text --profile=$1)
echo "AWS Account ID: $AWS_ACCOUNT_ID"
echo "AWS Access Key ID: $AWS_ACCESS_KEY"
echo "AWS Secret Access Key ID: $AWS_SECRET_KEY"
echo "AWS Region: $AWS_REGION"
packer build \
-var "aws_access_key=$AWS_ACCESS_KEY" \
-var "aws_secret_key=$AWS_SECRET_KEY" \
-var "aws_account_id=$AWS_ACCOUNT_ID" \
-var "aws_region=$AWS_REGION" \
packer.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment