From 84b3e5035a783dd18510a2d178b86a3c42f6dd2a Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Thu, 29 Aug 2024 20:14:26 +0200 Subject: [PATCH] s3_bucket - fix MethodNotAllowed in regions that don't support transfer 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 db552aa17f2056d91e7e4545b55ce14883674b45) --- changelogs/fragments/2266-acceleration-eu_north_1.yml | 3 +++ plugins/modules/s3_bucket.py | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/2266-acceleration-eu_north_1.yml diff --git a/changelogs/fragments/2266-acceleration-eu_north_1.yml b/changelogs/fragments/2266-acceleration-eu_north_1.yml new file mode 100644 index 00000000000..48a6fa9a76f --- /dev/null +++ b/changelogs/fragments/2266-acceleration-eu_north_1.yml @@ -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). diff --git a/plugins/modules/s3_bucket.py b/plugins/modules/s3_bucket.py index fd954de312b..764e90fc1e2 100644 --- a/plugins/modules/s3_bucket.py +++ b/plugins/modules/s3_bucket.py @@ -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