20

Using CloudFormation, I want to set some of the properties in AWS::S3::Bucket on an existing bucket. In other words, I don't want to create the bucket, I just want to enforce some of the settings. Here's an example of my cloudformation JSON:

"websitePreviewBucket": {
  "Type": "AWS::S3::Bucket",
  "Properties": {
    "AccessControl": "PublicRead",
    "VersioningConfiguration": {
      "Status": "Suspended"
    },
    "BucketName": "preview.website.com",
    "WebsiteConfiguration": {
      "IndexDocument": "index.html",
      "ErrorDocument": "error.html"
    }
  }
},

Not surprisingly, this fails in the cloudformation console:

The following resource(s) failed to create: [websitePreviewBucket].
preview.website.com already exists

I've created the bucket preview.website.com. I mean, this account "owns" that bucket. How can I set things like AccessControl and WebsiteConfiguration on an existing bucket with CloudFormation?

I've seen another question asking something similar, but it doesn't have a suitable answer.

7

I believe you are mistaken in using CloudFormation to modify your AWS infrastructure. CloudFormation's goal is to create AWS infrastructure in a templated fashion. It has been extended to allow for some management of the resources it creates, but managing existing infrastructure is not it's goal. From the welcome page:

AWS CloudFormation enables you to create and provision AWS infrastructure deployments predictably and repeatedly.

I believe the closest you will be able to get is to set a bucket policy on an existing bucket using AWS::S3::BucketPolicy. Beyond that you can use the AWS CLI S3 API to modify your bucket:

  • 13
    He might be coming from a different direction, but the fact that when you delete a stack, if the deletion policy for a S3 bucket is "retain" and then you go provision the same stack again, you'll have this error. Very annoying to say the least. At least with volumes you can snapshot and restore, there's absolutely nothing you can do with S3. – Sleeper Smith Nov 17 '14 at 14:30
  • Yet another direction is if you want to rename your stack. I downvoted because this answer assumes the OP wants to modify AWS infrastructure. This is often true only because of other limitations of CF, so there is nothing wrong with wanting to do this. – user239558 May 3 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.