AWS CDK Error: bucket policy already exists on bucket

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:

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.

Leave a Reply