Home > Mobile >  AWS SDK in Go does not take region information from profile
AWS SDK in Go does not take region information from profile

Time:12-17

Trying to follow the official example for listing buckets

    sess, err := session.NewSessionWithOptions(session.Options{
        Profile: "my-profile",
    })

    if err != nil {
        exitErrorf("Unable to create session, %v", err)
    }

    // Create S3 service client
    svc := s3.New(sess)
    result, err := svc.ListBuckets(nil)
    if err != nil {
        exitErrorf("Unable to list buckets, %v", err)
    }

Note that my-profile (residing in ~/.aws/credentials ) has region information associated

[my-profile]
aws_access_key_id=XXXXXXX
aws_secret_access_key=XXXXXXX
region=us-east-1

The program fails as follows:

Unable to list buckets, MissingRegion: could not find region configuration
exit status 1

edit: managed to work my way around this by prepending this line of code

os.Setenv("AWS_REGION", "us-east-1")

but I guess the proper way should be for the SDK to read the profile appropriately, no?

CodePudding user response:

region is set in ~/.aws/config.

~/.aws/config

[my-profile]
region=us-east-1

~/.aws/credentials

[my-profile]
aws_access_key_id=XXXXXXX
aws_secret_access_key=XXXXXXX
  • Related