I am using AWS Organizations from my master account to create sub-accounts like prod, dev, playground etc.
Inside the AWS Console it is easy to switch between the accounts by clicking the "Switch Role" button.
How do I achieve the same from the aws-cli using profiles? Can somebody list the least amount of steps necessary to achieve that?
When I search the internet (and I have) I find very different solutions and many of them involving creating new roles from scratch. However, I figure that I should be able to use the AWSServiceRoleForOrganizations role already created by AWS Organizations.
Thank you
3
Answers
I figured it out. In the credentials file add:
[master] aws_access_key_id = xxxxxxxxxxxxxxxxxxxxx aws_secret_access_key = xxxxxxxxxxxxxxxxxxxxx
[sub-account] role_arn = arn:aws:iam::XXXXXXXXXXXX:role/OrganizationAccountAccessRole source_profile = master
Where XXXXXXXXXXXX is the account number of the sub-account.
In your
~/.aws/config
and~/.aws/credentials
file you need to add different profiles and credentials .Place your keys in your
~/.aws/credentials
file.Modify your
~/.aws/config
file. Remember to Add the prefix ‘profile’Now you can switch between profile by using the
--profile
flagSimply set env var
AWS_PROFILE
to the respective profile to switch to another profileNote: Assuming you’ve configured different profiles in your system already
If you didn’t configure profiles yet in your local system, you can run the below command: