diff --git a/changelogs/fragments/1176-ssm-connection-plugin-region-fix.yml b/changelogs/fragments/1176-ssm-connection-plugin-region-fix.yml new file mode 100644 index 00000000000..a88a5ba84e9 --- /dev/null +++ b/changelogs/fragments/1176-ssm-connection-plugin-region-fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - aws_ssm - pull S3 bucket region for session generated for file transfer during playbooks (https://github.com/ansible-collections/community.aws/issues/1190). diff --git a/plugins/connection/aws_ssm.py b/plugins/connection/aws_ssm.py index 6e0d2a1ec60..e447e8cb8f0 100644 --- a/plugins/connection/aws_ssm.py +++ b/plugins/connection/aws_ssm.py @@ -534,7 +534,12 @@ def _flush_stderr(self, subprocess): def _get_url(self, client_method, bucket_name, out_path, http_method, profile_name, extra_args=None): ''' Generate URL for get_object / put_object ''' - region_name = self.get_option('region') or 'us-east-1' + + bucket_location = boto3.client('s3').get_bucket_location( + Bucket=(self.get_option('bucket_name')), + ) + region_name = bucket_location['LocationConstraint'] + client = self._get_boto_client('s3', region_name=region_name, profile_name=profile_name) params = {'Bucket': bucket_name, 'Key': out_path} if extra_args is not None: