Skip to content

Commit

Permalink
aws: fix issue with creating bucket in us-east-1
Browse files Browse the repository at this point in the history
Region us-east-1 isn't a valid parameter to a createBucket request.
This caused the following error when uploading:

Error:
    uploading variants:
    uploading image:
    ensuring bucket exists:
    creating bucket xxx:
    operation error S3:
    CreateBucket, https response error StatusCode: 400, RequestID: xxx, HostID: xx,
    api error InvalidLocationConstraint:
    The specified location-constraint is not valid

Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
  • Loading branch information
katexochen committed Oct 13, 2023
1 parent 8de7dd1 commit a77c604
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions aws/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,19 @@ func (u *Uploader) ensureBucket(ctx context.Context) error {
return nil
}
u.log.Printf("Bucket %s doesn't exist. Creating.", bucket)
_, err = s3C.CreateBucket(ctx, &s3.CreateBucketInput{
locationConstraint := s3types.BucketLocationConstraint(u.config.AWS.Region)
if u.config.AWS.Region == "us-east-1" {
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html#API_CreateBucket_RequestBody
// "If you don't specify a Region, the bucket is created in the US East (N. Virginia) Region (us-east-1)."
locationConstraint = s3types.BucketLocationConstraint("")
}
req := &s3.CreateBucketInput{
Bucket: &bucket,
CreateBucketConfiguration: &s3types.CreateBucketConfiguration{
LocationConstraint: s3types.BucketLocationConstraint(u.config.AWS.Region),
LocationConstraint: locationConstraint,
},
})
}
_, err = s3C.CreateBucket(ctx, req)
if err != nil {
return fmt.Errorf("creating bucket %s: %w", bucket, err)
}
Expand Down

0 comments on commit a77c604

Please sign in to comment.