aws-cdk: (s3): bucket already exists

I’m using aws-cdk-go https://github.com/aws/aws-cdk-go to deploy a stack with some functionalities. As far as I create a bucket resource using NewBucket call from github.com/aws/aws-cdk-go/awscdk/awss3 package I get an error that says the bucket already exists. I mean, I think this should check if it exists and omit creating again.

 0/101 |7:54:10 AM | CREATE_FAILED        | AWS::S3::Bucket                   | cdk-wiserentr-stack-dev-user-docs (cdkwiserentrstackdevuserdocsC2F72F08) cdk-wiserentr-stack-dev-user-docs already exists
	new Bucket (/tmp/jsii-kernel-aeePMk/node_modules/monocdk/lib/aws-s3/lib/bucket.js:589:26)
	\_ /tmp/jsii-runtime.481357249/lib/program.js:8367:58
	\_ Kernel._wrapSandboxCode (/tmp/jsii-runtime.481357249/lib/program.js:8795:24)
	\_ Kernel._create (/tmp/jsii-runtime.481357249/lib/program.js:8367:34)
	\_ Kernel.create (/tmp/jsii-runtime.481357249/lib/program.js:8108:29)
	\_ KernelHost.processRequest (/tmp/jsii-runtime.481357249/lib/program.js:9692:36)
	\_ KernelHost.run (/tmp/jsii-runtime.481357249/lib/program.js:9655:22)
	\_ Immediate._onImmediate (/tmp/jsii-runtime.481357249/lib/program.js:9656:46)
	\_ processImmediate (internal/timers.js:464:21)

Reproduction Steps

What did you expect to happen?

What actually happened?

Environment

  • CDK CLI Version : github.com/aws/aws-cdk-go/awscdk v1.124.0-devpreview
  • Framework Version:
  • Node.js Version: v16.9.1
  • OS : Linux 5.14.2-1-MANJARO
  • Language (Version): go version go1.16.7 linux/amd64

Other


This is 🐛 Bug Report

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

@urko-b I’ll sum up everything I’ve said so far.

Important things to know:

  • It is best practice to not specify the physical name of a resource. Please click on this link to learn about what exactly a physical name is. In this case, the physical name of the bucket you are creating is set with the BucketName prop.
  • There are multiple things that can happen when you make updates to existing resources. Please click on this link to learn about what might happen when you update an existing resource.
    • It is very important to know what happens when you make a change which requires a resource replacement. CloudFormation will create the replacement resource before destroying the existing resource. This is why it’s important to not specify the BucketName prop. According to AWS documentation:
      • Assigning physical names to resources has some disadvantages in AWS CloudFormation. Most importantly, any changes to deployed resources that require a resource replacement, such as changes to a resource’s properties that are immutable after creation, will fail if a resource has a physical name assigned.

  • CloudFormation will not attempt to recreate your resource unless you have made a change which requires a resource replacement
  • A change in the logical id of a resource will result in a resource replacement
    • You set the logical ID of the bucket here: awss3.NewBucket(stack, jsii.String(name))

What should you do?

OPTION 1 According to CDK documentation, delete your stack and then redeploy your stack. If you don’t make any additional changes after you redeploy which cause resource replacement, you won’t run into this issue anymore.

If you end up in a state like that, the only solution is to delete the AWS CloudFormation stack, then deploy the AWS CDK app again.

OPTION 2 According to CloudFormation documentation, specify a new physical name. If you don’t make any additional changes after you redeploy which cause resource replacement, you won’t run into this issue anymore.

You can’t perform an update that causes a custom-named resource to be replaced. If you must replace the resource, specify a new name.

OPTION 3 According to CDK best practices, do not specify the BucketName prop. You can make changes which cause resource replacement after this and you won’t run into this issue anymore.


I’ve thoroughly explained what’s happening at this point, so I’m going to close the issue. Please ping me if you’ve fully understood everything I’ve said and you’re still running into issues. Thanks! 😄

Hi @peterwoodworth But I mean. Why with event-bus creation is not happening the same? I think the NewBucket method should check if the bucket already exists and then do not create it. Otherwise S3 bucket creation using the cdk-stack code is not reusable. I only can run once the NewBucket creation… Is not friendly for developers.