Skip to main content

Python CLI for convenient emptying of S3 bucket

Project description

Avatar

Build Status Security Status Dependencies Status Published Version

S3Empty

S3Empty is a Python CLI for conveniently emptying an AWS S3 bucket.

This tool is useful when you want to delete all objects in a bucket before deleting the bucket itself. It handles versioned and non-versioned S3 buckets.

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

S3Empty console screenshot

Installation

pip3 install s3empty

Usage

Run S3Empty with specified bucket name:

s3empty --bucket-name some-bucket

Run S3Empty with a configuration file containing the bucket names:

s3empty --conf-file path/to/some-conf-file.yaml

Show help guide:

s3empty --help

Configuration

You can specify multiple bucket names in S3Empty configuration file and give it a name with .yaml extension, e.g. some-conf-file.yaml :

---
bucket_names:
  - some-bucket-1
  - some-bucket-2

And then call S3Empty:

s3empty --conf-file path/to/some-conf-file.yaml

The configuration file also supports Jinja template where environment variables are available for use. You can give this configuration template a name with .yaml.j2 extension, e.g. some-conf-file.yaml.j2 .

For example, if there is an environment variable ACCOUNT_ID=1234567 , you can specify it in the configuration file:

---
bucket_names:
  - some-{{ env.ACCOUNT_ID }}-bucket-1
  - some-{{ env.ACCOUNT_ID }}-bucket-2

And then call S3Empty:

s3empty --conf-file path/to/some-conf-file.yaml.j2

Permission

Here's an IAM policy with minimum permissions required by S3Empty:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "S3EmptyPolicy",
            "Effect": "Allow",
            "Action": [
                "s3:GetBucketVersioning",
                "s3:ListBucket",
                "s3:ListBucketVersions",
                "s3:DeleteObject",
                "s3:DeleteObjectVersion",
            ],
            "Resource": [
                "arn:aws:s3:::some-bucket",
                "arn:aws:s3:::some-bucket/*"
            ]
        }
    ]
}

Colophon

Developer's Guide

Build reports:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

s3empty-1.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

s3empty-1.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file s3empty-1.1.0.tar.gz.

File metadata

  • Download URL: s3empty-1.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for s3empty-1.1.0.tar.gz
Algorithm Hash digest
SHA256 9c3e4fceda768087fcbc3a8b65ce69d6739628693731982768751655d9a9396c
MD5 ed92a2796d10c24ddd0abe31c5084668
BLAKE2b-256 2ef4dc4fff57219f13fa5964461454e1e5df439e7d062ac7e14ac622fa3a1eaf

See more details on using hashes here.

File details

Details for the file s3empty-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: s3empty-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for s3empty-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f51018c6c5eccdfc2a15e62809a98ef7f3cac3ffc87c90b97a5dac3ab56832b8
MD5 0a990d7d71eb7093fe9ae44c883fc86f
BLAKE2b-256 2f84e77832048f9e450a48b58e32f7da5a209c781bfdb14da41408d904b6cea8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page