From 4defdfeb256c341f5e9b8ad0224400daf25d0b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Pedroche?= <129501338+raulpedroche@users.noreply.github.com> Date: Wed, 25 Oct 2023 09:10:07 +0200 Subject: [PATCH 1/3] Use HeadBucket instead of GetBucketLocation (#1979) --- plugins/connection/aws_ssm.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/connection/aws_ssm.py b/plugins/connection/aws_ssm.py index 5c2d6d57788..0c60292cbca 100644 --- a/plugins/connection/aws_ssm.py +++ b/plugins/connection/aws_ssm.py @@ -427,13 +427,12 @@ def _get_bucket_endpoint(self): ) # Fetch the location of the bucket so we can open a client against the 'right' endpoint # This /should/ always work - bucket_location = tmp_s3_client.get_bucket_location( + head_bucket = tmp_s3_client.head_bucket( Bucket=(self.get_option("bucket_name")), ) - if bucket_location["LocationConstraint"]: - bucket_region = bucket_location["LocationConstraint"] - else: - bucket_region = "us-east-1" + bucket_region = head_bucket.get("ResponseMetadata", {}).get("HTTPHeaders", {}).get("x-amz-bucket-region", None) + if bucket_region is None: + bucket_region = "us-east-1" if self.get_option("bucket_endpoint_url"): return self.get_option("bucket_endpoint_url"), bucket_region From c9a37589ae8633eba2908146ba505912ff7ddda2 Mon Sep 17 00:00:00 2001 From: Markus Bergholz Date: Fri, 7 Jun 2024 11:47:39 +0200 Subject: [PATCH 2/3] add changelog fragment --- changelogs/fragments/1979-use-headbucket.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/1979-use-headbucket.yml diff --git a/changelogs/fragments/1979-use-headbucket.yml b/changelogs/fragments/1979-use-headbucket.yml new file mode 100644 index 00000000000..d3f4a6af427 --- /dev/null +++ b/changelogs/fragments/1979-use-headbucket.yml @@ -0,0 +1,2 @@ +bugfixes: + - aws_ssm - use ``head_bucket`` to access bucket locations in foreign aws accounts (https://github.com/ansible-collections/community.aws/pull/1987). From 8dc063ae0ecaf10d1c27e51d9997dbeb275d8e3e Mon Sep 17 00:00:00 2001 From: Markus Bergholz Date: Fri, 7 Jun 2024 12:01:04 +0200 Subject: [PATCH 3/3] fix indent --- plugins/connection/aws_ssm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/connection/aws_ssm.py b/plugins/connection/aws_ssm.py index 0c60292cbca..d8b07c41c4d 100644 --- a/plugins/connection/aws_ssm.py +++ b/plugins/connection/aws_ssm.py @@ -432,7 +432,7 @@ def _get_bucket_endpoint(self): ) bucket_region = head_bucket.get("ResponseMetadata", {}).get("HTTPHeaders", {}).get("x-amz-bucket-region", None) if bucket_region is None: - bucket_region = "us-east-1" + bucket_region = "us-east-1" if self.get_option("bucket_endpoint_url"): return self.get_option("bucket_endpoint_url"), bucket_region