How to switch between multiple accounts with AWS SDK

0 votes

Im currently using the credential file (~/.aws/credentials) to initialize the SDK.

Credential File format.

aws_access_key_id={YOUR_ACCESS_KEY_ID}
aws_secret_access_key={YOUR_SECRET_ACCESS_KEY}

My requirement is to switch between multiple aws accounts. I'm currently trying to resolve this by overwriting the file with new credentials and re initialize the sdk. Is there any other efficient workaround to resolve this ? Thanks in Advance.

Aug 24, 2018 in AWS by bug_seeker
• 15,510 points
2,194 views

1 answer to this question.

+1 vote

You can define multiple profiles in ~/.aws/credentials and refer to the profile in your SDK initialization. See: A New and Standardized Way to Manage Credentials in the AWS SDKs which also shows examples for each language.

[default]
aws_access_key_id = ACCESS_KEY
aws_secret_access_key = SECRET_KEY
aws_session_token = TOKEN
[Alice]
aws_access_key_id = Alice_access_key_ID
aws_secret_access_key = Alice_secret_access_key
[Bob]
aws_access_key_id = Bob_access_key_ID
aws_secret_access_key = Bob_secret_access_key

answered Aug 24, 2018 by Priyaj
• 58,020 points

Related Questions In AWS

0 votes
1 answer

How to use AWS S3 REST API ListObjects(v2) with multiple parent/child bucket directories?

Here you have to use the ListObjectsV2 ...READ MORE

answered Feb 15, 2022 in AWS by anonymous
1,308 views
+1 vote
1 answer
0 votes
1 answer

How to use AWS CLI with Elastic Beanstalk?

You have to create a source bundle ...READ MORE

answered Sep 28, 2018 in AWS by Archana
• 4,170 points
2,201 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer

How to add SSL certificate to AWS EC2 with the help of new AWS Certificate Manager service

refer this link  https://aws.amazon.com/certificate-manager/faqs/ You can't install the certificates ...READ MORE

answered Jul 19, 2018 in AWS by Priyaj
• 58,020 points
1,862 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP