英文:
Setting Lifecycle configuration for Existing S3 Buckets in CloudFormation template file
问题
我想设置Amazon S3存储桶的生命周期配置,使对象在6个月后被删除,通过CloudFormation。
我想使用以下脚本将此配置添加到现有的存储桶中。
{
"AWSTemplateFormatVersion":"2010-09-09",
"Description":"设置生命周期配置",
"Resources":{
"S3Bucket":{
"Properties":{
"BucketName":"amazon-connect-test",
"AccessControl":"Private",
"LifecycleConfiguration":{
"Rules":[
{
"Id":"DeleteAfter6Months",
"Status":"Enabled",
"ExpirationInDays":180
}
]
}
},
"Type":"AWS::S3::Bucket"
}
}
}
但问题是它会创建一个新的S3存储桶,然后添加生命周期。
我想要的脚本将生命周期配置添加到现有的S3存储桶中。
任何帮助将不胜感激。
英文:
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.
答案1
得分: 1
编辑现有资源,目前由CloudFormation“未管理”,首先需要将其引入到CloudFormation中。
您可以管理资源,而无需将其删除并重新创建为堆栈的一部分。
英文:
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
答案2
得分: 0
参考@elias的答案,查看此AWS文档,该文档解释了如何将现有的S3存储桶导入为AWS CloudFormation堆栈。请确保按照文档中的描述,在CloudFormation模板的资源中添加属性"DeletionPolicy"。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论