简体   繁体   中英

AWS CloudFormation reusing the existing resource when creating or deploying new template

I am developing my CloudFormation template. I have an S3 bucket resource in my template with the following code.

StorageBucket:
    Type: AWS::S3::Bucket
    DeletionPolicy: Retain
    UpdateReplacePolicy: Retain
    Properties:
      BucketName: pathein-directory-storage
      AccessControl: PublicRead

As you can see I set the DeletionPolicy to Retain because I want to retain the Bucket and its data when the template is deleted. At some point, I explicitly deleted the template. But my S3 bucket was not deleted.

Now, I am trying to deploy my template again. But the deployment is failing because the bucket already exists with the same name. How can I figure my template to use the existing bucket if there is already one?

How can I figure my template to use the existing bucket if there is already one?

You have to import it into CFN as shown in:

Luckily, AWS::S3::Bucket is one of the resources that are supported for the import operation.

You begin the procedure in the console when you Create stack with existing resources :

在此处输入图片说明

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