AWS Empty Bucket
A custom S3 bucket with an ability to completely delete itself (even if it contains files within).
Remarks
The project is written by Laimonas Sutkus and is owned by iDenfy. This is an open source library intended to be used by anyone. iDenfy aims to share its knowledge and educate market for better and more secure IT infrastructure.
Related technology
This project utilizes the following technology:
- AWS (Amazon Web Services).
- AWS CDK (Amazon Web Services Cloud Development Kit).
- AWS CloudFormation.
- AWS S3 (Amazon Web Services Simple Storage Service).
Assumptions
This library project assumes the following:
- You have knowledge in AWS (Amazon Web Services).
- You have knowledge in AWS CloudFormation and AWS S3.
- You are managing your infrastructure with AWS CDK.
- You are writing AWS CDK templates with a python language.
Install
The project is built and uploaded to PyPi. Install it by using pip.
pip install aws-empty-bucket
Or directly install it through source.
./build.sh -ic
Description
Natively S3 buckets can not be deleted if they contain files. If you were to delete a bucket through CloudFormation, you would get a similar error message:
The bucket you tried to delete is not empty (Service: Amazon S3; Status Code: 409; Error Code: BucketNotEmpty; Request ID: ; S3 Extended Request ID: )
This gets especially annoying if a developer is spinning up and tearing down the infrastructure many times a day. Wouldn't it be awesome if S3 buckets could just be simply deleted in any case?
With this project you can create S3 buckets that can be deleted even if they
contain filed inside. A project exposes a class EmptyS3Bucket which can
be used exactly the same as a class Bucket provided by AWS CDK. Next time
you delete your stack, you will not see that error message again.
Examples
To create an S3 Bucket that can be easily deleted create an EmptyS3Bucket
instance in your stack. An example is given below:
from aws_cdk import core, aws_s3
from aws_empty_bucket.empty_s3_bucket import EmptyS3Bucket
class MainStack(core.Stack):
def __init__(self, scope: core.App) -> None:
super().__init__(
scope=scope,
id='MyCoolStack'
)
self.empty_bucket = EmptyS3Bucket(
self,
'MyCoolBucketThatCanBeDeleted',
access_control=aws_s3.BucketAccessControl.PRIVATE,
bucket_name='mybucket',
)
To delete inner S3 Bucket files, a custom resource with a lambda function as
as a backend is created too. EmptyS3Bucket exposes two properties:
backend and custom_resource. If you need to access them use the following:
from aws_empty_bucket.empty_s3_bucket import EmptyS3Bucket
empty_bucket = EmptyS3Bucket(...)
function = empty_bucket.backend
resource = empty_bucket.custom_resource
Release history
2.4.0
Add md files.
2.3.0
Dependency update 1.60.0 - 2.0.0.
2.2.0
Force AWS CDK dependency update to 1.44.0.
2.1.0
Dependencies update.
2.0.1
Do not use singleton lambdas since we are using roles for specific buckets.
2.0.0
Make a custom S3 bucket with inner-file deletion capabilities.
1.0.0
Initial project. Not tested. No extensive readme.
Metadata
Release files for aws-empty-bucket 2.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aws_empty_bucket-2.4.0.tar.gz | 6.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aws_empty_bucket-2.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.9 kB
Release files / aws_empty_bucket-2.4.0.tar.gz
| Download URL | aws_empty_bucket-2.4.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
93702c6a600976cff2bda21692cf54bd5b9cde9a6fa3c508a6332107587b49ad
|
|
BLAKE2b-256 checksum How to use checksums |
70e071bbc2a8da58675a0473589b040219ce5c6bfffbb97c2cca7fcf30c386a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/2.7.17
|
Release files / aws_empty_bucket-2.4.0-py3-none-any.whl
| Download URL | aws_empty_bucket-2.4.0-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d93c44178ddfec9eacc669725ed14de337f2915c27f0f95babc8fd204e6766a1
|
|
BLAKE2b-256 checksum How to use checksums |
32b8f37b9e13f07caeb2f05e99044d5dcad927694146db25d03e15987fec57df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/2.7.17
|
Security for aws-empty-bucket 2.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.