Setup Ansible and AWS CLI to use multiple access keys
1) Setup ~/.aws/credentials: ---- [personal] aws_access_key_id = A****Q aws_secret_access_key = 8****Z [dev] aws_access_key_id = A****Q aws_secret_access_key = M****E ---- 2) Setup ~/.aws/config: ---- [profile personal] region = us-west-2 output = table [profile dev] region = us-east-1 output = table ---- 3) Add to .bashrc: AWS_PROFILE="not defined";export AWS_PROFILE 4) create set-profile.sh: ---- #!/bin/bash export ANSIBLE_HOSTS=/home/ec2-user/Projects/automation-27/github/Ansible/AWS/tower-server/ec2.py export AWS_PROFILE=$1 #Remember to SOURCE this script ([prompt]:source set-profile.sh) ----
if using elastic beanstalk:
eb init --profile dev
Terraform
- Edit the file ~/.aws/credentials
- create a profile for each set of credentials:
[default] aws_access_key_id = A***Q aws_secret_access_key = f***0 region = us-west-2 output = table [business-account] aws_access_key_id = r***M aws_secret_access_key = c***T
- In your *.tf file, define your provider like so:
provider "aws" { region = "us-east-1" profile = "business-account" }