diff --git a/changelogs/fragments/1115-s3_object-scaleway.yml b/changelogs/fragments/1115-s3_object-scaleway.yml new file mode 100644 index 00000000000..da51448137e --- /dev/null +++ b/changelogs/fragments/1115-s3_object-scaleway.yml @@ -0,0 +1,2 @@ +bugfixes: +- s3_object - be more defensive when checking the results of ``s3.get_bucket_ownership_controls`` (https://github.com/ansible-collections/amazon.aws/issues/1115). diff --git a/plugins/modules/s3_object.py b/plugins/modules/s3_object.py index 4bf8c2c9380..54f267c9cde 100644 --- a/plugins/modules/s3_object.py +++ b/plugins/modules/s3_object.py @@ -1083,9 +1083,11 @@ def main(): exists = bucket_check(module, s3, bucket) if exists: try: - object_ownership = s3.get_bucket_ownership_controls(Bucket=bucket)['OwnershipControls']['Rules'][0]['ObjectOwnership'] - if object_ownership == 'BucketOwnerEnforced': - acl_disabled = True + ownership_controls = s3.get_bucket_ownership_controls(Bucket=bucket)['OwnershipControls'] + if ownership_controls.get('Rules'): + object_ownership = ownership_controls['Rules'][0]['ObjectOwnership'] + if object_ownership == 'BucketOwnerEnforced': + acl_disabled = True # if bucket ownership controls are not found except botocore.exceptions.ClientError: pass