RandomWits

life is too short for a diary




Empty s3 bucket and Delete using Jenkins and AWS CLI

Tags: jenkins aws

Author
Written by: Tushar Sharma
Featured image for Empty s3 bucket and Delete using Jenkins and AWS CLI

Amazon Simple Storage Service (s3) is a scalable object storage service provided by AWS. It allows users to store and retrieve vast amount of data, make it a fundamental building block for many applications hosted on AWS. Deleting a s3 bucket is a two step process: empty a s3 bucket and then delete a s3 bucket.

Deleting bucket without versioning

If a bucket has no versioning, we can empty s3 bucket using aws cli via jenkins

If there's versioning, then it will fail with the following error:

The bucket you tried to delete is not empty. You must delte all versions in the bucket.

Understanding s3 versioning and delete markers

  • Versioning: It allows you to preserve, retrieve, and restore every version of every object in a bucket. Once enabled, it cannot be suspended, only disabled.

  • Delete Markers: Once you delete a versioned object in s3, a delete marker is inserted. This marker becomes the current version, simulating a "delete" operatings but not actually removing the object.

Deleting bucket with versioning

We need to delete all versions and delete markers to empty the s3 bucket.


comments powered by Disqus