You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(s3): add grantReplicationPermission for IAM Role permissions (#34138)
### Issue # (if applicable)
Closes#34119
### Reason for this change
This change introduces a new method, grantReplicationPermission, to the aws-cdk-lib.aws_s3.Bucket construct. The purpose of this addition is to provide a more convenient and programmatic way for AWS CDK users to grant the necessary IAM permissions to a user-provided IAM Role that will be used for S3 bucket replication.
### Description of changes
This pull request includes the following code changes:
- Added a new public method `grantReplicationPermission` to the Bucket class.
- The implementation of this method programmatically attaches the necessary IAM permissions for S3 bucket replication to the provided identity. This change refactors the `renderReplicationConfiguration` method by extracting the IAM permission granting functionality into a dedicated `grantReplicationPermission` method.
- unit and integ test
- The README was updated to show that users can now grant replication rights to custom IAM roles.
### Describe any new or updated permissions being added
No new IAM permissions are being added at the CDK level. The permissions granted by the `grantReplicationPermission` method are the same as those already handled internally by the existing replication configuration logic. This change simply exposes that functionality through a dedicated method.
### Description of how you validated changes
- Added unit tests to verify the functionality of the `grantReplicationPermission` method, ensuring that the correct IAM policies are attached to the provided role. Notably, the unit tests specifically cover scenarios where an explicit `replicationRole` is provided.
- Existing integration tests were run to confirm that no regressions were introduced by this change. In addition, the existing test scenario `integ.bucket-replication-use-custom-role.ts` was refactored to use the new `grantReplicationPermission` method instead of manually attaching the required permissions to the IAM role, and its behavior was verified to remain equivalent.
### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy file name to clipboardExpand all lines: packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.import-source.js.snapshot/asset.530055f7515b3f0a47900f5df37e729ba40ca977b2d07b952bdefa2b8f883f42.bundle/index.js
Copy file name to clipboardExpand all lines: packages/@aws-cdk-testing/framework-integ/test/aws-s3/test/integ.bucket-replication-use-custom-role.js.snapshot/BucketReplicationTestStack.assets.json
Copy file name to clipboardExpand all lines: packages/@aws-cdk-testing/framework-integ/test/aws-s3/test/integ.bucket-replication-use-custom-role.js.snapshot/BucketReplicationTestStack.template.json
Copy file name to clipboardExpand all lines: packages/@aws-cdk-testing/framework-integ/test/aws-s3/test/integ.bucket-replication-use-custom-role.js.snapshot/ReplicationIntegDefaultTestDeployAssert2C07A074.assets.json
Copy file name to clipboardExpand all lines: packages/@aws-cdk-testing/framework-integ/test/aws-s3/test/integ.bucket-replication-use-custom-role.js.snapshot/ReplicationIntegDefaultTestDeployAssert2C07A074.template.json
Copy file name to clipboardExpand all lines: packages/@aws-cdk-testing/framework-integ/test/aws-s3/test/integ.bucket-replication-use-custom-role.js.snapshot/manifest.json
Copy file name to clipboardExpand all lines: packages/@aws-cdk-testing/framework-integ/test/aws-s3/test/integ.bucket-replication-use-custom-role.js.snapshot/tree.json
0 commit comments