Skip to content

Commit fa58965

Browse files
authored
Fix detection of ssm connection bucket region (#1428)
Fix detection of ssm connection bucket region Fix detection of ssm connection bucket region by ensuring that the boto client is created normally and able to use supported credential sources SUMMARY PR #1176 introduced detection of an S3 bucket's region to handle cases where the bucket is in a different region than the SSM connection itself. This change did not use the preferred mechanism for creating client objects, which caused it to not have access to credentials from all supported sources. It also broke the ability to use this plugin in partitions other than aws. (e.g. aws-us-gov). This change fixes this by building the bucket location client using _get_boto_client and the region for the connection to ensure it is both getting the proper credentials and starting in a region from the same partition as the client itself. From the default global region (or a hard-coded region), it will detect the bucket's region and continue S3 API calls using the bucket's own region. Fixes bug introduced from #1176 Fixes #1413 ISSUE TYPE Bugfix Pull Request COMPONENT NAME aws_ssm connection plugin Reviewed-by: Markus Bergholz <git@osuv.de> Reviewed-by: Alina Buzachis <None> Reviewed-by: Mark Chappell <None>
1 parent 099b831 commit fa58965

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- aws_ssm - fixes S3 bucket region detection by ensuring boto client has correct credentials and exists in correct partition (https://github.com/ansible-collections/community.aws/pull/1428).

plugins/connection/aws_ssm.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,12 +534,14 @@ def _flush_stderr(self, subprocess):
534534
def _get_url(self, client_method, bucket_name, out_path, http_method, profile_name, extra_args=None):
535535
''' Generate URL for get_object / put_object '''
536536

537-
bucket_location = boto3.client('s3').get_bucket_location(
537+
region_name = self.get_option('region') or 'us-east-1'
538+
539+
bucket_location = self._get_boto_client('s3', region_name=region_name, profile_name=profile_name).get_bucket_location(
538540
Bucket=(self.get_option('bucket_name')),
539541
)
540-
region_name = bucket_location['LocationConstraint']
542+
bucket_region_name = bucket_location['LocationConstraint']
541543

542-
client = self._get_boto_client('s3', region_name=region_name, profile_name=profile_name)
544+
client = self._get_boto_client('s3', region_name=bucket_region_name, profile_name=profile_name)
543545
params = {'Bucket': bucket_name, 'Key': out_path}
544546
if extra_args is not None:
545547
params.update(extra_args)

0 commit comments

Comments
 (0)