A Python library to estimate AWS S3 storage costs using Cost Explorer
Project description
AWS S3 Storage Cost Estimator
A lightweight Python library to estimate Amazon S3 storage costs using the AWS Cost Explorer API.
It focuses only on storage-related charges (TimedStorage, EarlyDelete fees) and generates clear text reports with cost breakdowns.
📌 Features
- Estimate S3 storage costs for a specific bucket
- Supports multiple reporting periods:
- Daily
- Weekly
- Quarterly
- Annual
- Produces clean text-based reports with tables and breakdowns
- Saves reports with timestamps in an output directory
- Supports AWS Cost Explorer resource-level granularity (if enabled)
⚙️ Installation
Clone this repository and install dependencies:
git clone https://github.com/<your-username>/<your-repo>.git
cd <your-repo>
pip install boto3
Make sure your AWS credentials are configured via one of:
aws configure(recommended)- Environment variables:
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKEN - IAM Role (if running on AWS services)
🚀 Usage
Run the Example
python example.py
This will:
- Estimate costs for the bucket defined in
example.py - Generate a report in
./storage_cost_reports/ - Print the report path to the console
Example Report Output
================================================================================
AWS S3 STORAGE COST REPORT FOR BUCKET: my-example-bucket
================================================================================
Generated (UTC): 2025-09-21 22:45:11
Region: us-east-1
STORAGE COST TABLE
------------------------------------------------------------
Period Date Range Total Cost (USD)
------------------------------------------------------------
Day 2025-09-20 to 2025-09-21 $1.23
Week 2025-09-14 to 2025-09-21 $8.45
Quarter 2025-06-23 to 2025-09-21 $34.12
Year 2024-09-21 to 2025-09-21 $120.55
DETAILS FOR DAY [2025-09-20 to 2025-09-21]
------------------------------------------------------------
Bucket Cost (USD)
------------------------------------------------------------
my-example-bucket $1.23
Other $0.00
================================================================================
Note: Costs are storage-related only (e.g., TimedStorage and EarlyDelete fees).
Bucket breakdown requires Cost Explorer resource-level granularity enabled.
================================================================================
🔧 Custom Usage
You can import and use the library in your own script:
from S3StorageCostEstimator import S3StorageCostEstimator
# Initialize estimator (default region is us-east-1)
estimator = S3StorageCostEstimator(region_name="us-east-1")
# Estimate storage costs
report_path = estimator.cost_estimate(bucket_name="my-example-bucket")
print(f"Report saved at: {report_path}")
Parameters
bucket_name(str): S3 bucket to analyzeoutput_dir(str, optional): Directory for reports (default:./storage_cost_reports)periods(list[str], optional): Periods to calculate (default: all:day,week,quarter,year)
📦 Requirements
- Python 3.8+
- boto3
- AWS account with Cost Explorer enabled
📝 License
This project is licensed under the MIT License.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file s3_cost_estimator-1.1.0.tar.gz.
File metadata
- Download URL: s3_cost_estimator-1.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecebbaae4cf35c70205e03235b13bf1da546d9670197cfd5c4332edbfc2e2a44
|
|
| MD5 |
13793fc8eb4c81a80597d6c79fc9630e
|
|
| BLAKE2b-256 |
b43a59082caf1b0443be5b823534bae44c96da7202c621399b95f27554513230
|
File details
Details for the file s3_cost_estimator-1.1.0-py3-none-any.whl.
File metadata
- Download URL: s3_cost_estimator-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50eda258cd9aa6f50a17e3d0604baae32bf40f7bd8b224ed7e0d1f85aed7e39a
|
|
| MD5 |
df43c49a960291a297a8879ad3784fef
|
|
| BLAKE2b-256 |
b3c507e653955daef88fc64a4a3846af607fcc663c0f01481cd80544a20a3fd5
|