Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I set the default profile for AWS CLI in a Powershell session

What am I doing wrong here?

My %UserProfile%.aws\config file looks like this:

[profile foo]
output = json
region = us-east-1

My %UserProfile%.aws\credentials file looks like this:

[foo]
aws_access_key_id = BAOAIGKMPRBTLBNOSCZQ
aws_secret_access_key = OcML0LadbbD3Nt+PmAlhzNTmoS6Xx9M3M6DkBx4m

So there is no default profile configured: I want to set only for the Powershell session.

In Powershell I run:

set AWS_PROFILE=foo

Then I try to execute a cli command, but it says it cannot find the credentials:

PS D:\> aws ec2 describe-instances
You must specify a region. You can also configure your region by running "aws configure".
PS D:\> aws ec2 describe-instances --region us-east-1
Unable to locate credentials. You can configure credentials by running "aws configure".
like image 725
cbp Avatar asked Sep 06 '25 13:09

cbp


1 Answers

Ah, I figured out that in Powershell you can't set environment variables using the set command. (Aside: I wonder what Powershell thinks it's doing when you use the set command... it doesn't give an error message).

The correct way is:

$env:AWS_PROFILE="foo"
like image 172
cbp Avatar answered Sep 09 '25 15:09

cbp