Search code examples
amazon-web-servicesamazon-cloudfront

AWS 'Bucket already exists' - how to "migrate" existing resources to CloudFormation?


We have already created some infrastructure manually and with terraform, including some s3 buckets. In the future I would like to use pure CloudFormation to define the infrastructure as code.

So I created a CloudFormation yaml definition which references an existing bucket:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  TheBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-existing-bucket-name

When I try to apply it, execution fails, with CloudFormation stack event:

The following resource(s) failed to update: [TheBucket].
12:33:47 UTC+0200   UPDATE_FAILED   AWS::S3::Bucket TheBucket
  my-existing-bucket-name already exists

How can I start managing existing resources with CloudFormation without recreating them? Or is it impossible by design?


Solution

  • You will need to create a new bucket and sync the data from the old bucket to the new bucket. I have not seen a way to use an modify an existing S3 bucket.