From a77c6044d6c07f1912fc1822f4c6b40d5e11f9a2 Mon Sep 17 00:00:00 2001 From: Paul Meyer <49727155+katexochen@users.noreply.github.com> Date: Fri, 13 Oct 2023 15:25:27 +0200 Subject: [PATCH] aws: fix issue with creating bucket in us-east-1 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> --- aws/uploader.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/aws/uploader.go b/aws/uploader.go index 3785f6a..714bd03 100644 --- a/aws/uploader.go +++ b/aws/uploader.go @@ -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) }