You have created multiple S3 buckets using AWS CloudFormation Templates.
You have added a DeletionPolicy for each template to clean up all S3 buckets created during stack creation and deletion.
Upon some research, you find that some S3 buckets are not getting deleted.
Which of the following could be the reason?
Click on the arrows to vote for the correct answer
A. B. C. D.Correct Answer - B.
For Amazon S3 buckets, we need to ensure that all objects are deleted before deleting S3 buckets by DeletionPolicy of CloudFormation Template.
Option A is incorrect as Default DeletionPolicy for Amazon S3 bucket is Delete.
Option C is incorrect as even though AWS CloudFormation has permission to delete S3 buckets, we need to ensure that no objects are present in S3 buckets before deleting the S3 bucket.
Option D is incorrect as the Default option for DeletionPolicy for S3 buckets is to delete S3 buckets once Stack is deleted.
But you need to ensure that all objects in S3 buckets are deleted to delete the S3 bucket.
For more information on DeletionPolicy with CloudFormation templates, refer to the following URL-
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.htmlWhen creating S3 buckets using AWS CloudFormation templates, it is important to ensure that the necessary steps are taken to delete them when the stack is deleted. This helps to avoid incurring unnecessary costs and also helps to maintain a clean environment. In this scenario, you have created multiple S3 buckets using AWS CloudFormation Templates, and you have added a DeletionPolicy for each template to clean up all S3 buckets created during stack creation and deletion. However, you have discovered that some S3 buckets are not getting deleted.
There could be several reasons why some S3 buckets are not getting deleted, but the most likely reasons are as follows:
A. Default DeletionPolicy for Amazon S3 bucket is Retain: When an S3 bucket is created, the default DeletionPolicy for Amazon S3 bucket is set to Retain. This means that the bucket will not be deleted when the stack is deleted, even if you have added a DeletionPolicy to the CloudFormation template. Therefore, you need to modify the DeletionPolicy to delete the S3 bucket after the stack is deleted.
D. Modify DeletionPolicy to delete S3 bucket after stack is deleted: To ensure that S3 buckets are deleted when the stack is deleted, you need to modify the DeletionPolicy in your CloudFormation template to delete the S3 bucket after the stack is deleted. This ensures that the bucket is deleted even if the default DeletionPolicy for Amazon S3 bucket is set to Retain.
B. Ensure that all objects in S3 buckets are deleted before bucket is deleted: Another reason why S3 buckets may not be getting deleted is if there are objects in the bucket that are not getting deleted. In this case, you need to ensure that all objects in the S3 bucket are deleted before the bucket is deleted. You can do this by adding a DeletionPolicy to delete all objects in the bucket before the bucket is deleted.
C. Ensure that CloudFormation Stack has permissions to delete S3 buckets: Another reason why S3 buckets may not be getting deleted is if the CloudFormation stack does not have permissions to delete the S3 buckets. In this case, you need to ensure that the CloudFormation stack has the necessary permissions to delete the S3 buckets. You can do this by adding the appropriate permissions to the CloudFormation stack.
In summary, to ensure that S3 buckets are deleted when the CloudFormation stack is deleted, you need to modify the DeletionPolicy in your CloudFormation template to delete the S3 bucket after the stack is deleted. You also need to ensure that all objects in the S3 bucket are deleted before the bucket is deleted and that the CloudFormation stack has permissions to delete the S3 buckets.