func()

in scripts/go/curconvert/curconvert.go [176:204]


func (c *CurConvert) getBucketLocation(bucket string, arn string, externalID string) (string, error) {

	// Init Session
	sess, err := session.NewSession(&aws.Config{Region: aws.String("us-east-1")})
	if err != nil {
		return "", err
	}

	// if needed set creds for AssumeRole and reset session
	if len(arn) > 0 {
		sess = sess.Copy(&aws.Config{Credentials: c.getCreds(arn, externalID, sess)})
	}

	// Get Bucket location
	svc := s3.New(sess)
	res, err := svc.GetBucketLocation(&s3.GetBucketLocationInput{
		Bucket: aws.String(bucket),
	})

	if err != nil {
		return "", err
	}

	// empty string returned for buckets existing in us-east-1! https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGETlocation.html
	if res.LocationConstraint == nil || len(*res.LocationConstraint) < 1 {
		return "us-east-1", nil
	}
	return *res.LocationConstraint, nil
}