Thursday, July 15, 2021

Create multiple profiles in aws and switch between them

 Create AWS Profile

Ref: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html


In production environment, it's easier to switch to different AWS IAM user or IAM role identity by export AWS_PROFILE=PROFILE_NAME.


Instead of using default profile created by above aws configure, you can create a named AWS Profile eks-demo`in two ways:

1. aws configure --profile eks-demo

2. create profile entry in ~/.aws/credentials file


To create a new AWS Profile entry in ~/.aws/credentials file, do the followings:

vim ~/.aws/credentials

Enter i key and paste below lines into the file


[eks-demo] 
aws_access_key_id=YOUR_ACCESS_KEY 
aws_secret_access_key=YOUR_SECRET_ACCESS_KEY
aws_region = YOUR_REGION 


Hit escape key and type :wq! to save and exit out from Vim.

Then check if new profile can be authenticated

export AWS_PROFILE=eks-demo

# successful output
aws sts get-caller-identity
{
    "UserId": "xxxxxxxxx",
    "Account": "12321313123131",
    "Arn": "arn:aws:iam::1231231231231:user/eks-demo"
}

No comments:

Post a Comment