Question:
I am trying to create a lambda and a DynamoDB using CDK in java. When I try to do ‘CDK Deploy’ I face following error:
1 2 3 4 5 |
11:20:30 AM | CREATE_FAILED | AWS::S3::BucketPolicy | StagingBucketPolicy The bucket policy already exists on bucket xyz-cdk-toolkit-stagingbucket-1hpv60vcdqk7s. CDK Version: 1.48.0 |
Answer:
This error occurs directly from CloudFormation, and as it says, the bucket you are adding the policy to, already has an existing one. CloudFormation does not allow for replacement/modification of bucket policies that were created outside of its control.
This is a security measure preventing you by accidentally changing existing policies.
If you want to control the bucket policy with CDK (or CloudFormation) you have to recreate it in CDK, delete the original one, and create using the CDK.