Skip to content
This repository was archived by the owner on Aug 19, 2026. It is now read-only.
This repository was archived by the owner on Aug 19, 2026. It is now read-only.

Optimize CreateBucket by Omitting LocationConstraint for us-east-1 #78

Description

@0xJacobs

The CreateBucket function currently sets LocationConstraint in CreateBucketConfiguration for all regions, including us-east-1. According to the Amazon S3 API Reference for CreateBucket, this is redundant for us-east-1:

"If you don’t specify a LocationConstraint, the bucket is created in the US East (N. Virginia) Region (us-east-1) by default."

Specifying LocationConstraint for us-east-1 is unnecessary, as the AWS SDK defaults to this region when CreateBucketConfiguration is omitted. This optimization aligns the code with AWS best practices and improves clarity.

Proposed Solution

Update the CreateBucket function to conditionally omit CreateBucketConfiguration when the region is us-east-1:

func (s *Client) CreateBucket(ctx context.Context, name, region string) error {
    input := &s3.CreateBucketInput{
        Bucket: aws.String(name),
    }
    if region != "us-east-1" {
        input.CreateBucketConfiguration = &types.CreateBucketConfiguration{
            LocationConstraint: types.BucketLocationConstraint(region),
        }
    }
    _, err := s.s3Client.CreateBucket(ctx, input)
    return err
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions