“ MissingRegion”:找不到区域配置,但是我在〜/ .aws.config中有它

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?

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.