Skip to content

V3: Fixed an issue where IAmazonS3.EnsureBucketExists(Async) was throwing an exception if S3 bucket already exists in the executing account. #3826

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

Open
wants to merge 1 commit into
base: aws-sdk-net-v3.7-development
Choose a base branch
from

Conversation

ashishdhingra
Copy link
Contributor

@ashishdhingra ashishdhingra commented May 19, 2025

Description

Fixed an issue where IAmazonS3.EnsureBucketExists(Async) was throwing an exception if S3 bucket already exists in the executing account.

Kindly note below:

  • Refer Using the handle method to filter inner exceptions on how to handle exceptions when using async Task based version.
  • After handling exception for async version, we return Task.FromResult(0). This is because:
    • If we return the original Task object, it re-throws exception in the calling awaited thread.
    • Task.CompletedTask doesn't exist in NET45 target.

Motivation and Context

Issue #3807

Testing

  • Added integration test.
  • Dry-run DRY_RUN-423d72f9-65a0-487d-bf80-a41832d2bead pending.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

… an exception if S3 bucket already exists in the executing account.
@@ -145,7 +145,21 @@ Task ICoreAmazonS3.MakeObjectPublicAsync(string bucket, string objectKey, bool e

Task ICoreAmazonS3.EnsureBucketExistsAsync(string bucketName)
{
return this.PutBucketAsync(bucketName);
Task task = this.PutBucketAsync(bucketName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should just use the async/await something like.

async Task ICoreAmazonS3.EnsureBucketExistsAsync(string bucketName)
{
   try
   {
        await this.PutBucketAsync(bucketName);
   }
   catch(BucketAlreadyOwnedByYouException)
   {
   }
}

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

Successfully merging this pull request may close these issues.

2 participants