Skip to content

Commit

Permalink
s3_bucket - fix MethodNotAllowed in regions that don't support transf…
Browse files Browse the repository at this point in the history
…er acceleration (#2267)

fixes: #2266
SUMMARY
While #2202 (combined with #2222) fixes the issue for the aws-gov partition, the aws partition throws a different Error (MethodNotAllowed).
I suspect the two different exceptions are a side effect of how AWS implement the Gov-Cloud partition vs the normal partition.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
s3_bucket
ADDITIONAL INFORMATION
See also: #2266

Reviewed-by: GomathiselviS
(cherry picked from commit db552aa)
  • Loading branch information
tremble authored and patchback[bot] committed Aug 29, 2024
1 parent 703782b commit 84b3e50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/2266-acceleration-eu_north_1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- s3_bucket - fixes ``MethodNotAllowed`` exceptions caused by fetching transfer acceleration state in regions that don't support it (https://github.com/ansible-collections/amazon.aws/issues/2266).
8 changes: 5 additions & 3 deletions plugins/modules/s3_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,11 @@ def handle_bucket_accelerate(s3_client, module: AnsibleAWSModule, name: str) ->
except is_boto3_error_code(["NotImplemented", "XNotImplemented"]) as e:
if accelerate_enabled is not None:
module.fail_json_aws(e, msg="Fetching bucket transfer acceleration state is not supported")
except is_boto3_error_code("UnsupportedArgument") as e: # pylint: disable=duplicate-except
# -- Transfer Acceleration is not available in AWS GovCloud (US).
# -- https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-s3.html#govcloud-S3-diffs
except is_boto3_error_code(["UnsupportedArgument", "MethodNotAllowed"]) as e: # pylint: disable=duplicate-except
# - Transfer Acceleration is not available in AWS GovCloud (US) and throws UnsupportedArgument.
# https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-s3.html#govcloud-S3-diffs
# - Transfer Acceleration is not available in some AWS regions and throws MethodNotAllowed
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/transfer-acceleration.html
module.warn("Tranfer acceleration is not available in S3 bucket region.")
accelerate_enabled_result = False
except is_boto3_error_code("AccessDenied") as e: # pylint: disable=duplicate-except
Expand Down

0 comments on commit 84b3e50

Please sign in to comment.