Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Mohiiit opened this issue Jan 6, 2025 · 0 comments
Open

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

Mohiiit opened this issue Jan 6, 2025 · 0 comments

Comments

@Mohiiit
Copy link
Contributor

Mohiiit commented Jan 6, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant