-
Notifications
You must be signed in to change notification settings - Fork 4.5k
(aws-cdk-lib/aws-s3): Too many BucketPolicy resources defined when defining/attaching BucketPolicy constructs to Buckets #30148
Copy link
Copy link
Closed
Labels
@aws-cdk/aws-s3Related to Amazon S3Related to Amazon S3bugThis issue is a bug.This issue is a bug.effort/mediumMedium work item – several days of effortMedium work item – several days of effortp2
Description
Describe the bug
Situation:
- Create two (2)
Bucketconstructs in aStack - Create two (2)
BucketPolicyconstructs in the sameStack - Identify one of the buckets as an "access logging" bucket for the other bucket.
Result:
- three (3)
AWS::S3::BucketPolicyCloudFormation resources are synthesized - all three wind up getting created when the
Stackis deployed - two of the three point to the same AWS S3 bucket
- net result is that the "last"
BucketPolicy(not the UNION of theBucketPolicyconstructs) "wins" - The resulting
BucketPolicydoes not match what is defined in the CDK application.
Expected Behavior
Expected Behavior is either:
- a) only the explicitly indicated
BucketPolicyis created - b) the implicitly created
BucketPolicyand the explicitly createdBucketPolicyis what is synthesized/deployed - c) an error is indicated that the explicit
BucketPolicywould NOT be appropriate if it lacks the necessary permissions (in this case, allowing the AWS logging service to be able to write to the identified access logging bucket)
Current Behavior
Result:
- three (3)
AWS::S3::BucketPolicyCloudFormation resources are synthesized - all three wind up getting created when the
Stackis deployed - two of the three point to the same AWS S3 bucket
- net result is that the "last"
BucketPolicy(not the UNION of theBucketPolicyconstructs) "wins" - The resulting
BucketPolicydoes not match what is defined in the CDK application.
Reproduction Steps
See above.
Possible Solution
Suggested Behavior:
- c) an error is indicated that the explicit
BucketPolicyis NOT appropriate since it lacks the necessary permissions (in this case, allowing the AWS logging service to be able to write to the identified access logging bucket)
Or a recommendation to use .addToResourcePolicy() rather than creating explicit BucketPolicy constructs.
Additional Information/Context
Sample code can be provided on request.
CDK CLI Version
2.141.0
Framework Version
aws-cdk-lib@2.138.0
Node.js Version
v20.12.2
OS
MacOS
Language
TypeScript
Language Version
typescript@5.3.3
Other information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-s3Related to Amazon S3Related to Amazon S3bugThis issue is a bug.This issue is a bug.effort/mediumMedium work item – several days of effortMedium work item – several days of effortp2