Skip to content

Commit

Permalink
Do not set LocationConstraint when creating a S3 bucket in us-east-1 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hmizuma authored Oct 30, 2020
1 parent b7ae42a commit 2fee818
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/aws/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,20 @@ func createBucket(
lifecycleExpirationDays int64) (retry bool, err error) {

lg.Info("creating S3 bucket", zap.String("name", bucket))
_, err = s3API.CreateBucket(&s3.CreateBucketInput{
createBucketInput := &s3.CreateBucketInput{
Bucket: aws.String(bucket),
CreateBucketConfiguration: &s3.CreateBucketConfiguration{
LocationConstraint: aws.String(region),
},
// https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
// vs. "public-read"
ACL: aws.String("private"),
})
}
// Setting LocationConstraint to us-east-1 fails with InvalidLocationConstraint. This region is handled differerntly and must be omitted.
// https://github.com/boto/boto3/issues/125
if region != "us-east-1" {
createBucketInput.CreateBucketConfiguration = &s3.CreateBucketConfiguration{
LocationConstraint: aws.String(region),
}
}
_, err = s3API.CreateBucket(createBucketInput)
alreadyExist := false
if err != nil {
// https://docs.aws.amazon.com/AWSEC2/latest/APIReference/errors-overview.html
Expand Down

0 comments on commit 2fee818

Please sign in to comment.