skip to Main Content

I want to set the Amazon S3 bucket lifeCycle configuration where the objects will be deleted after 6 months through CloudFormation.
I want to add this configuration to an existing bucket using the following script.

{
   "AWSTemplateFormatVersion":"2010-09-09",
   "Description":"Set Lifecycle Configuration",
   "Resources":{
      "S3Bucket":{
         "Properties":{
            "BucketName":"amazon-connect-test",
            "AccessControl":"Private",
            "LifecycleConfiguration":{
               "Rules":[
                  {
                     "Id":"DeleteAfter6Months",
                     "Status":"Enabled",
                     "ExpirationInDays":180
                  }
               ]
            }
         },
         "Type":"AWS::S3::Bucket"
      }
   }
}

but the problem is that it will create a new S3 bucket and then add the LifeCycle.
I want the script that will add the LifeCycle configuration to an existing S3 bucket.
any help would be appreciated.

2

Answers


  1. To edit existing resources that are currently "unmanaged" by CloudFormation, first you need to bring it into CloudFormation

    You can manage your resources regardless of where they were created without having to delete and re-create them as part of a stack

    Login or Signup to reply.
  2. Expanding on @elias’s answer, refer this AWS documentation which explains about importing an existing S3 bucket as an AWS CloudFormation stack. Make sure to add the attribute "DeletionPolicy" in the resource of CloudFormation template as described in the documentation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search