1

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??

whitebear
  • 11,200
  • 24
  • 114
  • 237
  • 3
    Bucket name must be unique, not only on your account but globally across all accounts. Additionally, if you delete a bucket with that name recently, it could take a couple of hours to see the name as available again. – OARP Jan 11 '22 at 14:34

1 Answers1

2

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.

gshpychka
  • 8,523
  • 1
  • 11
  • 31
  • 1
    Wow thank you very much. It's very clear explanation and solving .it saves my times. This project is given by my predecessor and I am just testing in my personal account. T – whitebear Jan 12 '22 at 06:28