Skip to main content

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 in an output directory
  • Supports AWS Cost Explorer resource-level granularity (if enabled)

⚙️ Installation

pip install s3-cost-estimator

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 analyze
  • output_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

s3_cost_estimator-3.0.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

s3_cost_estimator-3.0.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file s3_cost_estimator-3.0.0.tar.gz.

File metadata

  • Download URL: s3_cost_estimator-3.0.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for s3_cost_estimator-3.0.0.tar.gz
Algorithm Hash digest
SHA256 2f724c1914f89aa01518e20c4877f84106071a2725faead8f20f166d26dfb0fc
MD5 073e0c3e54c9b11ee6b4669300efcb16
BLAKE2b-256 0d363d948f972ffd50223396874306997786f3372180aecb126ad635b14be5b8

See more details on using hashes here.

File details

Details for the file s3_cost_estimator-3.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for s3_cost_estimator-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b05d9d16afcb460ab681d113e1bc7593075e3ed206cc717f13a1f7ec34e302ad
MD5 c8157ce5e209ec91288f45024dfa8058
BLAKE2b-256 e8a8d24ba18638e4d0c09431a9a9b4eb790a0df477f020fd4e11a4758c71f05c

See more details on using hashes here.

Supported by

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