Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

807
Views
AWS CDK Error: bucket policy already exists on bucket

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:

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
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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.

over 4 years ago · Santiago Trujillo Report

0

As I mentioned in comment above in response to @Marcin's reply, this blog helped me solve the problem. Following are the steps I followed:

  1. Copied the cloud formation yaml snippet to a file named s3-bucket.yml provided in the blog.
  2. Used aws cli command to first create this bucket: aws cloudformation deploy --template-file resources/s3-bucket.yml --stack-name my-bucket-stack1
  3. Fired this CDK command to deploy my stack: cdk deploy --toolkit-stack-name my-bucket-stack1

These steps created my stack.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!