Reputation: 14906
My code:
sess = session.Must(session.NewSessionWithOptions(session.Options{
Profile: "gms-ai",
}))
My ~/.aws/config
:
[default]
output = json
region = us-east-1
[profile gms-ai]
output = json
region = us-east-2
But for example this is working snipet from my deployment script:
AWS_PROFILE=gms-ai \
aws lambda update-function-code...
So looks like aws cli
do read region
but AWS SDK ignore it?
Upvotes: 3
Views: 3947
Reputation: 1602
This is expected behavior. See here:
By default the SDK will only load the shared credentials file's (~/.aws/credentials) credentials values, and all other config is provided by the environment variables, SDK defaults, and user provided aws.Config values.
If the AWS_SDK_LOAD_CONFIG environment variable is set, or SharedConfigEnable option is used to create the Session the full shared config values will be loaded. This includes credentials, region, and support for assume role. In addition the Session will load its configuration from both the shared config file (~/.aws/config) and shared credentials file (~/.aws/credentials). Both files have the same format.
Link here.
So just set the AWS_SDK_LOAD_CONFIG environment variable to read the config.
Upvotes: 2