Skip to content
This repository was archived by the owner on May 24, 2025. It is now read-only.
This repository was archived by the owner on May 24, 2025. It is now read-only.

Avoid Hardcoding us-east-1 in Bucket Creation Logic #201

@Mohiiit

Description

@Mohiiit

Description:
The current implementation of the create_bucket function hardcodes the region us-east-1 when creating an S3 bucket. AWS provides enums for region constraints, and hardcoding a specific region can lead to reduced flexibility and potential region mismatch errors.

Current Code Snippet:

async fn create_bucket(&self, bucket_name: &str) -> Result<()> {
    if self.bucket_location_constraint.as_str() == "us-east-1" {
        self.client.create_bucket().bucket(bucket_name).send().await?;
        return Ok(());
    }

    let bucket_configuration = Some(
        CreateBucketConfiguration::builder().location_constraint(self.bucket_location_constraint.clone()).build(),
    );

    self.client
        .create_bucket()
        .bucket(bucket_name)
        .set_create_bucket_configuration(bucket_configuration)
        .send()
        .await?;

    Ok(())
}

Proposed Change:

  • Replace the hardcoded check for us-east-1 with a comparison against AWS-provided enums for region constraints.
  • Ensure that the condition correctly handles regions that may not require an explicit location_constraint.

Expected Outcome:

  • The code dynamically adapts to AWS enums for region constraints.
  • Avoids potential errors or failures due to hardcoded region checks.

Additional Context:
A previous attempt to address this issue resulted in failing tests. Careful validation and testing are required to ensure correctness this time.

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