AWS Account Switch in Visual Studio Code

0

I have multiple AWS accounts and I am using VSCode. The credential and config files are like this

credentials

[default]
aws_access_key_id=foo
aws_secret_access_key=bar

[profilname]
aws_access_key_id=foo
aws_secret_access_key=bar

config

[default]
region=eu-central-1
output=json

[profile profilname]
region=eu-central-1
output=json

My problem is, that I can switch between the accounts and the status line in VSCode shows the correct account even the AWS plugin shows the same, but if I check the ressources with the CLI for example with aws s3 ls, I always get the of the default account. In the explorer of the AWS plugin there are the correct ressources.

If I use aws s3 ls --profile profilname, I get the correct ressources for this account. What is my fail? How can I change securely so a mistaken change to the false account is excluded? My workaround is to change the credentials of the default account.

3 Answers
1

This is normal behaviour.

If you name the profile to be default it will become default profile i.e. when no --profile param in the command.

More on default profile

If you spend more time using account1, you can make it the default by setting the AWS_DEFAULT_PROFILE environment variable. When the default environment variable is set, you do not need to specify the profile on each command.

Linux, OS X Example:

$ export AWS_DEFAULT_PROFILE=account1 $ aws dynamodb list-tables Windows Example:

$ set AWS_DEFAULT_PROFILE=account1 $ aws s3 ls

Other option is to set the AWS_profile environment variable at the command line via export AWS_PROFILE=profile_name. Setting the env variable changes the default profile until the end of your shell session or until you set the variable to a different value.

profile picture
EXPERT
answered 10 months ago
0

Thanks for your fast answer.

When I use the command set AWS_DEFAULT_PROFILE=account1 the account did not change. Wether in the VSCode AWS Plugin nor in the status line. The result of the command aws s3 ls are the ressources of the default account

I tried set AWS_PROFILE=profile_name before and there nothing happens too.

In stackoverflow I saw a post where a user means the credentials must be unset and then set

unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
export AWS_PROFILE=[profile-name-here]

But I don't understand where to do this. I am confused and deperate. :S

robin
answered 10 months ago
0

Close VS code and open again. Write

aws sts get-caller-identity

It should by default show your default profile creds. To change it export another profile.

profile picture
answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions