whitebear
whitebear

Reputation: 12433

CREATE_FAILED | AWS::S3::Bucket, the invisible bucket is exist?

I am using aws-cdk and $cdk deploy to deploy some stacks.

However, there comes error like this

21:12:30 | CREATE_FAILED        | AWS::S3::Bucket                             | S3BucketStaticResourceB341FA19
si2-s3-sbu-mytest-xxx-static-resource-5133297d-91 already exists

Normally this kind of error, I can find the item exists in AWS console.

However in this case, $aws s3 ls doesn't show the bucket named this.

Why does this occur or where should I fix??

Upvotes: 2

Views: 1462

Answers (1)

gshpychka
gshpychka

Reputation: 11512

Generally, it is a good idea to avoid explicitly providing physical names for resources you create with CDK.

The documentation explains the reasoning:

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. If you end up in that state, the only solution is to delete the AWS CloudFormation stack, then deploy the AWS CDK app again. See the AWS CloudFormation documentation for details.

So if you introduce a change that requires your bucket to be replaced, you'll see the aforementioned error.

In your specific case, it is probably an S3-specific issue that bucket names are globally unique - across all accounts and regions, as stated by @Omar Rosadio in the comments. This makes naming your buckets yourself an especially bad idea.

If you don't pass the bucketName property when creating the bucket, CDK will generate a unique name for you, so you don't have to worry about this, and I suggest doing so.

Upvotes: 2

Related Questions