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). diff --git a/plugins/connection/aws_ssm.py b/plugins/connection/aws_ssm.py index 5c2d6d57788..d8b07c41c4d 100644 --- a/plugins/connection/aws_ssm.py +++ b/plugins/connection/aws_ssm.py @@ -427,12 +427,11 @@ 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 = 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"):