Reputation: 2568
I have a cloudformation template for S3 and I'm trying to create it once and then update it. But when i try to update it it fails with the error message <bucket_name> already exists in stack <arn:id>
.
"S3Bucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"Properties": {
"AccessControl": "BucketOwnerFullControl",
"BucketName": {
"Fn::Join": [
"-",
[
{
"Fn::GetAtt": [
"VPCInfo",
"VPCname"
]
},
{
"Ref": "BucketName"
}
]
]
},
"LoggingConfiguration": {
"DestinationBucketName": {
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"VPCInfo",
"VPCname"
]
},
"-s3logs"
]
]
},
"LogFilePrefix": {
"Fn::Join": [
"-",
[
{
"Fn::GetAtt": [
"VPCInfo",
"VPCname"
]
},
{
"Ref": "AWS::StackName"
}
]
]
}
},
"VersioningConfiguration": {
"Status": "Enabled"
}
}
}
Second try update where BucketName & TopicName
are passed as params
"S3Bucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"Properties": {
"AccessControl": "BucketOwnerFullControl",
"BucketName": {
"Fn::Join": [
"-",
[
{
"Fn::GetAtt": [
"VPCInfo",
"VPCname"
]
},
{
"Ref": "BucketName"
}
]
]
},
"LoggingConfiguration": {
"DestinationBucketName": {
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"VPCInfo",
"VPCname"
]
},
"-s3logs"
]
]
},
"LogFilePrefix": {
"Fn::Join": [
"-",
[
{
"Fn::GetAtt": [
"VPCInfo",
"VPCname"
]
},
{
"Ref": "AWS::StackName"
}
]
]
}
},
"NotificationConfiguration": {
"TopicConfigurations": [
{
"Topic": {
"Fn::Join": [
"",
[
"arn:aws:sns:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":function:",
{
"Ref": "TopicName"
}
]
]
},
"Event": "s3:ObjectCreated:*",
"Filter": {
"S3Key": {
"Rules": [
{
"Name": "suffix",
"Value": {
"Ref": "FileSuffix"
}
}
]
}
}
},
{
"Topic": {
"Fn::Join": [
"",
[
"arn:aws:sns:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":function:",
{
"Ref": "TopicName"
}
]
]
},
"Event": "s3:ObjectRemoved:*",
"Filter": {
"S3Key": {
"Rules": [
{
"Name": "suffix",
"Value": {
"Ref": "FileSuffix"
}
}
]
}
}
}
]
},
"VersioningConfiguration": {
"Status": "Enabled"
}
}
}
What's the correct way to update S3 stack? The reason why I'm trying to do it twice is due to this -> https://aws.amazon.com/premiumsupport/knowledge-center/unable-validate-destination-s3/
Upvotes: 0
Views: 399
Reputation: 12253
I believe you are deleting the CFT and recreating it. Your problem is "DeletionPolicy": "Retain"
which retains the S3 bucket even after you delete the CFT. If you update the existing one, you should be fine.
Just delete the bucket manually if you delete CFT or change "DeletionPolicy": "Retain"
to "DeletionPolicy": "Delete"
Upvotes: 1