简体   繁体   中英

AWS CDK S3 Bucket Creation Error - Bucket_Name already exisits

I am new to using CloudFormation / CDK and am having trouble figuring out to deploy my stacks without error. Currently I am using the python CDK to create a bucket. This bucket will hold model files and I need to ensure that the bucket deployed in this stack retains data over time / new deployments. From my initial tests, it seems that if bucket_name is not specified, the CDK will randomly generate a new bucket name on deployment, which is not ideal.

Here is the snippet used to create the bucket:

bucket = aws_s3.Bucket(self, "smartsearch-bucket", bucket_name= 'mybucketname')

The first time I run cdk deploy , there are no problems and the bucket is created. The second time I run cdk deploy , I get an error stating that my S3 bucket already exists. What else is needed so that I can redeploy my stack using a predetermined S3 bucket name?

I ran into the same issue, and it was due to the reason that bucket was already created by me manually earlier for some testing , NOT by ECS stack initially. Deleting the bucket definitely makes ECS deployment to work fine, as it did for you and I tested this running the deployment multiple times. Ensure that no ECS resources are pre-created manually.

The way ECS would identify if it has to re-create a resource is via these tags:

在此处输入图像描述

The S3 bucket names are global, it means that if someone else on a different account has chosen this name, it wont work, you should provide a very unique name for your bucket.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM