Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AWS SDK in Go does not take region information from profile

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading