Skip to main content

Retrieves AWS Monthly Costs

Project description

aws-monthly-costs

A Python CLI tool to retrieve and report AWS monthly costs across accounts, business units, and services using AWS Cost Explorer API.

๐Ÿšจ Recent Breaking Changes (v0.1.0+)

If you're upgrading from an earlier version (pre-v0.1.0), please note:

  • --profile is now REQUIRED: Previously optional with a hardcoded default, now you must explicitly specify an AWS profile for security
  • --include-ss renamed to --include-shared-services: More descriptive argument name

See the Migration Guide below for upgrade instructions.

Features

  • ๐Ÿ“Š Generate cost reports by account, business unit, or service
  • ๐Ÿ“ˆ Support for daily average cost calculations
  • ๐Ÿ“‘ Automatic analysis Excel file with charts and formatted tables (default output)
  • ๐Ÿ’พ Optional export of individual reports in CSV or Excel format (XLSX)
  • ๐Ÿ”ง Customizable cost aggregations and groupings
  • ๐Ÿค Shared services cost allocation across business units
  • โœ… Comprehensive test coverage (226 tests, 93% overall coverage)
  • ๐Ÿ”’ Security-focused design (no vulnerabilities)
  • ๐Ÿ“ Well-documented with inline docstrings

Requirements

  • Python 3.10 or higher
  • AWS credentials configured (via ~/.aws/config)
  • Required AWS IAM permissions:
    • ce:GetCostAndUsage (AWS Cost Explorer)
    • organizations:ListAccounts (AWS Organizations)
    • organizations:DescribeAccount (AWS Organizations)
    • sts:GetCallerIdentity (AWS STS)

Installation

From Source

git clone https://github.com/whoDoneItAgain/aws-monthly-costs.git
cd aws-monthly-costs
pip install -e .

Dependencies

The tool requires the following Python packages (automatically installed):

  • boto3>=1.42.17 - AWS SDK for Python
  • pyyaml>=6.0.3 - YAML configuration file parsing
  • openpyxl>=3.1.5 - Excel file generation

Usage

Quick Start

The simplest command to get started:

amc --profile your-aws-profile

This will:

  1. Query AWS Cost Explorer for the previous month's costs
  2. Run the three main report modes (account, bu, service)
  3. Generate an analysis Excel file (./outputs/aws-monthly-costs-analysis.xlsx) with:
    • Formatted comparison tables
    • Pie charts showing cost distribution
    • Business unit, service, and account breakdowns
    • Daily average calculations

Note: Individual report files are NOT generated unless explicitly requested with --output-format.

AWS Profile Setup

Before running the tool, ensure your AWS credentials are configured:

# Configure AWS CLI credentials
aws configure --profile your-profile-name

# Verify the profile exists
aws sts get-caller-identity --profile your-profile-name

The profile should have the required IAM permissions listed in the Requirements section.

Advanced Usage

Custom Time Periods

# Use month mode for last 2 full months (default)
amc --profile your-aws-profile --time-period month

# Use a specific date range
amc --profile your-aws-profile --time-period 2024-01-01_2024-12-31

# Use year mode for two-year comparison (requires 24+ months of data)
amc --profile your-aws-profile --time-period year

Month Mode (default): When you use --time-period month, the tool will:

  1. Fetch the last 2 complete months of AWS cost data
  2. Generate comparison tables and charts for these 2 months

Year Mode: When you use --time-period year, the tool will:

  1. Fetch the last 24 months of AWS cost data
  2. Split the data into two complete 12-month periods for comparison
  3. Generate a separate year-analysis.xlsx file with:
    • Yearly cost totals comparison
    • Daily average costs for each year period
    • Monthly average costs for each year period
    • Comparative charts and formatted tables

Requirements for Year Mode:

  • At least 24 consecutive months of AWS cost data
  • Data should be non-overlapping and complete
  • If insufficient data exists, you'll receive an actionable error message

Example Error Messages:

Error: Insufficient data for year analysis. Provide at least 24 consecutive, 
non-overlapping months for two-year comparison. Currently have 18 months.

To generate year analysis, provide at least 24 consecutive months of data.
Use a custom date range like: --time-period YYYY-MM-DD_YYYY-MM-DD with 24+ months

Generate Individual Report Files

By default, only the analysis Excel file is created. Use --output-format to generate individual reports:

# Generate individual CSV reports (plus analysis file)
amc --profile your-aws-profile --output-format csv

# Generate individual Excel reports (plus analysis file)
amc --profile your-aws-profile --output-format excel

# Generate both CSV and Excel individual reports (plus analysis file)
amc --profile your-aws-profile --output-format both

Include Shared Services Allocation

Allocate shared services costs across business units based on percentages defined in your configuration:

amc --profile your-aws-profile --include-shared-services

Run Specific Modes

# Run only specific modes
amc --profile your-aws-profile --run-modes account bu

# Include daily average calculations
amc --profile your-aws-profile --run-modes account bu service account-daily bu-daily service-daily

Note: The analysis Excel file is only generated when all three main modes (account, bu, service) are run.

Custom Configuration File

# Use a custom configuration file
amc --profile your-aws-profile --config-file /path/to/custom-config.yaml

Debug Logging

Enable detailed logging for troubleshooting:

amc --profile your-aws-profile --debug-logging

Security Note: Debug logs may contain AWS account IDs and cost data. Use with caution in sensitive environments.

Complete Examples

# Full command with all options
amc --profile production-readonly \
    --config-file ./config/prod-config.yaml \
    --time-period 2024-01-01_2024-12-31 \
    --output-format both \
    --include-shared-services \
    --run-modes account bu service account-daily bu-daily service-daily \
    --debug-logging

# Year-level analysis with 24 months of data
amc --profile production-readonly \
    --time-period 2023-01-01_2024-12-31 \
    --include-shared-services \
    --debug-logging

# Year mode (automatically fetches last 24 months)
amc --profile production-readonly \
    --time-period year \
    --include-shared-services

Command-Line Options

Run amc --help to see all available options:

amc --help
Option Required Default Description
--profile Yes None AWS profile name from ~/.aws/config
--config-file No src/amc/data/config/aws-monthly-costs-config.yaml Path to configuration YAML file
--aws-config-file No ~/.aws/config Path to AWS credentials config file
--include-shared-services No False Allocate shared services costs across business units
--run-modes No account bu service Report types to generate (space-separated)
--time-period No month Time period: month for last 2 months, year for year-level analysis (24+ months), or YYYY-MM-DD_YYYY-MM-DD for custom range
--output-format No None Individual report format: csv, excel, or both (omit for analysis file only)
--debug-logging No False Enable debug-level logging

Configuration File

The configuration file defines business units, shared services, and service aggregation rules. Example structure:

# Business unit definitions
business_units:
  Engineering:
    - "123456789012"  # Account IDs
    - "234567890123"
  Operations:
    - "345678901234"
  Marketing:
    - "456789012345"

# Shared services accounts (optional)
shared_services:
  accounts:
    - "567890123456"
  allocation:  # Percentage allocation across BUs
    Engineering: 50
    Operations: 30
    Marketing: 20

# Service name aggregation rules (optional)
service_aggregation:
  "Compute":
    - "Amazon Elastic Compute Cloud - Compute"
    - "Amazon EC2 Container Service"
  "Storage":
    - "Amazon Simple Storage Service"
    - "Amazon Elastic Block Store"

For a complete example, see the included src/amc/data/config/aws-monthly-costs-config.yaml file.

Output Files

All output files are generated in the ./outputs/ directory.

Analysis Excel File (Default Output)

File: aws-monthly-costs-analysis.xlsx

Generated automatically when running the three main modes (account, bu, service). This is the primary output and contains:

Worksheets

  1. BU Costs - Business unit monthly totals comparison

    • Last 2 months side-by-side
    • Difference and % Difference columns
    • Pie chart showing BU cost distribution
    • Conditional formatting (green for savings, red for increases)
  2. BU Costs - Daily Avg - Business unit daily average comparison

    • Accounts for different month lengths and leap years
    • Same comparison format as monthly totals
  3. Top Services - Top 10 services + "Other" category

    • Monthly totals with pie chart
    • Aggregated based on configuration rules
  4. Top Services - Daily Avg - Daily average for top services

  5. Top Accounts - Top 10 accounts + "Other" category

    • Monthly totals with pie chart
    • Account names from AWS Organizations
  6. Top Accounts - Daily Avg - Daily average for top accounts

Features

  • Formatted Tables: Bold headers, light blue background (#D9E1F2)
  • Conditional Formatting:
    • ๐ŸŸข Green for cost decreases (savings)
    • ๐Ÿ”ด Red for cost increases
  • Pie Charts: Large, easy-to-read with data labels on slices
  • Number Formatting:
    • Currency format with 2 decimal places
    • Percentage format for differences
  • Auto-adjusted Columns: Proper width for immediate readability
  • Smart Filtering: Zero-cost business units omitted from charts

Individual Report Files (Optional)

Generated only when --output-format is specified. Files are created in ./outputs/ with the naming pattern:

  • CSV format: aws-monthly-costs-{run_mode}.csv
  • Excel format: aws-monthly-costs-{run_mode}.xlsx

Where {run_mode} is one of: account, bu, service, account-daily, bu-daily, service-daily

CSV Format

Simple comma-separated values file with:

  • Header row with column names
  • Data rows with cost values
  • Easy to import into other tools

Excel Format

Formatted Excel workbook with:

  • Bold headers with light blue background
  • Auto-adjusted column widths
  • Proper number formatting
  • Professional appearance

Examples:

# Analysis file only (default)
amc --profile prod
# Creates: ./outputs/aws-monthly-costs-analysis.xlsx

# Analysis file + CSV reports
amc --profile prod --output-format csv
# Creates: ./outputs/aws-monthly-costs-analysis.xlsx
#          ./outputs/aws-monthly-costs-account.csv
#          ./outputs/aws-monthly-costs-bu.csv
#          ./outputs/aws-monthly-costs-service.csv

# Year analysis file (when using --time-period year)
amc --profile prod --time-period year
# Creates: ./outputs/aws-monthly-costs-analysis.xlsx
#          ./outputs/aws-monthly-costs-year-analysis.xlsx

Year Analysis Excel File (Year Mode)

File: aws-monthly-costs-year-analysis.xlsx

Generated when using --time-period year option. Requires at least 24 consecutive months of data. This file contains:

Worksheets

  1. BU Costs - Yearly - Business unit yearly totals comparison

    • Two most recent complete 12-month periods side-by-side
    • Difference and % Difference columns
    • Pie chart showing BU cost distribution for most recent year
    • Conditional formatting (green for savings, red for increases)
  2. BU Costs - Daily Avg - Business unit daily average comparison

    • Accounts for different month lengths and leap years
    • Same comparison format as yearly totals
  3. BU Costs - Monthly Avg - Business unit monthly average comparison

    • Average cost per month across each 12-month period
    • Useful for normalized comparisons
  4. Top Services - Yearly - Top 10 services yearly totals + "Other"

    • Yearly totals with pie chart
    • Aggregated based on configuration rules
  5. Top Services - Daily Avg - Daily average for top services

  6. Top Services - Monthly Avg - Monthly average for top services

  7. Top Accounts - Yearly - Top 10 accounts yearly totals + "Other"

    • Yearly totals with pie chart
    • Account names from AWS Organizations
  8. Top Accounts - Daily Avg - Daily average for top accounts

  9. Top Accounts - Monthly Avg - Monthly average for top accounts

Features

  • Formatted Tables: Bold headers, blue background (#4472C4)
  • Conditional Formatting:
    • ๐ŸŸข Green for cost decreases (savings)
    • ๐Ÿ”ด Red for cost increases
  • Pie Charts: Large, easy-to-read with data labels on slices
  • Number Formatting:
    • Currency format with 2 decimal places
    • Percentage format for differences
  • Auto-adjusted Columns: Proper width for immediate readability
  • Year Labels: Clear identification of time periods (e.g., "Year 1 (2023-Jan - 2023-Dec)")

Architecture Overview

The application follows a modular architecture with clear separation of concerns:

aws-monthly-costs/
โ”œโ”€โ”€ src/amc/
โ”‚   โ”œโ”€โ”€ __main__.py              # Entry point & orchestration (785 lines)
โ”‚   โ”œโ”€โ”€ constants.py             # Named constants (56 lines)
โ”‚   โ”œโ”€โ”€ version.py               # Version information
โ”‚   โ”œโ”€โ”€ data/config/             # Default configuration files
โ”‚   โ”œโ”€โ”€ reportexport/            # Report generation (2438 lines total)
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py          # Imports/exports only (16 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ exporters.py         # CSV/Excel export functions (130 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ analysis.py          # Analysis table creation (983 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ year_analysis.py     # Year-level analysis (635 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ analysis_tables.py   # Table utilities (300 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ calculations.py      # Calculation utilities (58 lines)
โ”‚   โ”‚   โ”œโ”€โ”€ formatting.py        # Formatting utilities (221 lines)
โ”‚   โ”‚   โ””โ”€โ”€ charts.py            # Chart creation utilities (95 lines)
โ”‚   โ””โ”€โ”€ runmodes/                # Cost calculation modules
โ”‚       โ”œโ”€โ”€ common.py            # Shared utilities (133 lines)
โ”‚       โ”œโ”€โ”€ account/             # Account cost calculations
โ”‚       โ”‚   โ”œโ”€โ”€ __init__.py     # Imports/exports only (8 lines)
โ”‚       โ”‚   โ””โ”€โ”€ calculator.py   # Business logic (168 lines)
โ”‚       โ”œโ”€โ”€ bu/                  # Business unit calculations
โ”‚       โ”‚   โ”œโ”€โ”€ __init__.py     # Imports/exports only (9 lines)
โ”‚       โ”‚   โ””โ”€โ”€ calculator.py   # Business logic (169 lines)
โ”‚       โ””โ”€โ”€ service/             # Service cost calculations
โ”‚           โ”œโ”€โ”€ __init__.py     # Imports/exports only (9 lines)
โ”‚           โ””โ”€โ”€ calculator.py   # Business logic (191 lines)
โ””โ”€โ”€ tests/                       # Comprehensive test suite (226 tests)

Key Components

1. Main Module (__main__.py)

  • Purpose: Entry point and orchestration
  • Responsibilities:
    • Parse command-line arguments
    • Load and validate configuration
    • Create AWS sessions
    • Coordinate runmode execution
    • Trigger report generation
  • Key Functions:
    • parse_arguments() - CLI argument parsing
    • configure_logging() - Logging setup
    • load_configuration() - YAML config loading with validation
    • parse_time_period() - Date range parsing and validation
    • create_aws_session() - AWS session creation with validation
    • main() - Main orchestration logic

2. Constants Module (constants.py)

  • Purpose: Centralized constants and magic values
  • Contains:
    • Run mode identifiers (RUN_MODE_ACCOUNT, RUN_MODE_BUSINESS_UNIT, etc.)
    • Output format constants (OUTPUT_FORMAT_CSV, OUTPUT_FORMAT_EXCEL, etc.)
    • AWS API dimension and metric names
    • Valid choices for CLI arguments

3. Run Modes

Each runmode is a separate module that:

  • Queries AWS Cost Explorer API
  • Processes and aggregates cost data
  • Calculates daily averages (accounting for leap years)
  • Returns structured cost dictionaries

Account Mode (runmodes/account/)

  • Retrieves costs grouped by AWS account
  • Supports pagination for large account lists
  • Extracts account names from AWS Organizations
  • Returns top N accounts by cost

Business Unit Mode (runmodes/bu/)

  • Aggregates account costs into business units
  • Supports shared services allocation
  • Single optimized API call (not separate calls per BU)
  • Handles leap year calculations correctly

Service Mode (runmodes/service/)

  • Groups costs by AWS service
  • Applies service aggregation rules from config
  • Returns top N services by cost
  • Handles service name variations

4. Report Export (reportexport/)

  • Purpose: Generate output files (CSV, Excel, analysis workbooks)

  • Export Modules:

    • exporters.py - CSV/Excel export functions
    • analysis.py - Analysis Excel workbook creation
    • year_analysis.py - Year-level analysis Excel workbook
  • Utility Modules:

    • analysis_tables.py - Table creation utilities
    • calculations.py - Percentage and difference calculations
    • formatting.py - Excel styling and formatting utilities
    • charts.py - Pie chart creation and configuration
  • Main API (__init__.py): Imports/exports only (following Python best practices)

Data Flow

1. User runs CLI command
   โ†“
2. Parse arguments & load configuration
   โ†“
3. Create & validate AWS session
   โ†“
4. For each run mode:
   a. Query AWS Cost Explorer API
   b. Process & aggregate data
   c. Calculate daily averages
   โ†“
5. Generate reports:
   a. Optional: Individual CSV/Excel files
   b. Default: Analysis Excel file (if all 3 modes run)
   โ†“
6. Save to ./outputs/ directory

Design Patterns

  • Single Responsibility: Each module has one clear purpose
  • DRY (Don't Repeat Yourself): Helper functions avoid code duplication
  • Configuration Over Convention: Behavior customizable via YAML
  • Fail-Fast: Comprehensive input validation with clear error messages
  • Modular Architecture: Easy to extend with new run modes or export formats

Performance Optimizations

Applied by Performance-Optimizer Agent (see AGENT_HANDOFF.md):

  • Reduced API calls: BU mode makes 1 API call instead of 2 (50% reduction)
  • Efficient sorting: Direct list slicing instead of intermediate dict conversions
  • Optimized Excel generation: Single-pass column width calculation
  • Set-based filtering: O(1) lookups for account categorization

Troubleshooting

Common Issues

"AWS profile does not exist"

Error: AWS profile 'xyz' does not exist in /home/user/.aws/config

Solution:

# List available profiles
aws configure list-profiles

# Configure a new profile
aws configure --profile your-profile-name

# Verify the profile
aws sts get-caller-identity --profile your-profile-name

"AWS profile session is not valid"

Error: AWS profile (xyz) session is not valid

Causes:

  • Invalid or expired credentials
  • Incorrect profile configuration
  • Missing IAM permissions

Solutions:

# Verify credentials work
aws sts get-caller-identity --profile your-profile-name

# Reconfigure the profile
aws configure --profile your-profile-name

# Check if using SSO (requires login)
aws sso login --profile your-profile-name

"Configuration file not found"

Error: Configuration file not found: /path/to/config.yaml

Solution:

# Use the default config
amc --profile your-profile-name

# Or specify correct path
amc --profile your-profile-name --config-file /correct/path/to/config.yaml

# Copy example config
cp src/amc/data/config/aws-monthly-costs-config.yaml my-config.yaml

"Invalid time period format"

Error: Invalid time period format

Solution:

# Use 'month' for last 2 months (default)
amc --profile your-profile-name --time-period month

# Or use correct date format: YYYY-MM-DD_YYYY-MM-DD
amc --profile your-profile-name --time-period 2024-01-01_2024-12-31

"Missing required configuration keys"

Error: Configuration file is missing required key(s)

Solution: Ensure your configuration file has all required sections:

# Minimum required structure
business_units:
  YourBU:
    - "123456789012"  # At least one account ID

# Optional but recommended
shared_services:
  accounts: []
  allocation: {}

service_aggregation: {}

Missing IAM Permissions

Error: An error occurred (AccessDeniedException) when calling the GetCostAndUsage operation

Solution: Ensure your AWS IAM user/role has these permissions:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ce:GetCostAndUsage",
        "organizations:ListAccounts",
        "organizations:DescribeAccount",
        "sts:GetCallerIdentity"
      ],
      "Resource": "*"
    }
  ]
}

Analysis File Not Generated

Issue: Running the tool but analysis Excel file is not created

Cause: Analysis file requires all three main modes (account, bu, service) to be run.

Solution:

# Use default run modes (includes all 3)
amc --profile your-profile-name

# Or explicitly specify all 3
amc --profile your-profile-name --run-modes account bu service

Empty or Incorrect Cost Data

Issue: Reports show $0 or unexpected values

Possible Causes:

  1. Time period has no cost data
  2. AWS Organizations not configured
  3. Cost allocation tags not enabled
  4. Incorrect business unit account mappings in config

Solutions:

# Enable debug logging to see API responses
amc --profile your-profile-name --debug-logging

# Verify your time period
amc --profile your-profile-name --time-period 2024-01-01_2024-01-31

# Check AWS Cost Explorer in the console to verify data exists

Debug Logging

Enable debug logging for detailed diagnostic information:

amc --profile your-profile-name --debug-logging

Debug logs include:

  • AWS API request/response details
  • Configuration values
  • Cost calculation steps
  • Account and service mapping

Security Note: Debug logs may contain:

  • AWS account IDs
  • Cost data
  • Configuration details

Do not share debug logs in public forums without sanitizing sensitive data.

Getting Help

  1. Check Documentation: Review this README and TESTING.md
  2. Review Configuration: Ensure your YAML config is valid
  3. Enable Debug Logging: Use --debug-logging for detailed diagnostics
  4. Check AWS Console: Verify data exists in AWS Cost Explorer
  5. Review Permissions: Ensure IAM permissions are correct
  6. File an Issue: Open a GitHub issue with debug logs (sanitized)

Migration Guide

Upgrading from Earlier Versions to v0.1.0+

Version 0.1.0 introduced breaking changes to improve security and code quality. Follow these steps to upgrade:

Step 1: Update Command-Line Arguments

Breaking Change 1: --profile is now required

โŒ Old (pre-v0.1.0):

# Profile was optional with hardcoded default
amc --include-ss
amc  # Used hardcoded default profile

โœ… New (v0.1.0+):

# Profile is now REQUIRED (more secure)
amc --profile your-profile-name --include-shared-services

Breaking Change 2: --include-ss renamed to --include-shared-services

โŒ Old (pre-v0.1.0):

amc --profile prod --include-ss

โœ… New (v0.1.0+):

amc --profile prod --include-shared-services

Step 2: Update Scripts and Automation

If you have scripts, CI/CD pipelines, or cron jobs calling amc, update them:

Before (pre-v0.1.0):

#!/bin/bash
# Old script
amc --include-ss --output-format csv

After (v0.1.0+):

#!/bin/bash
# Updated script
amc --profile production-readonly --include-shared-services --output-format csv

Step 3: Review Configuration File

The configuration file format has not changed, but validation is now stricter:

# Ensure all required keys are present
business_units:
  Engineering:
    - "123456789012"

# Optional sections can be empty but should exist
shared_services:
  accounts: []
  allocation: {}

service_aggregation: {}

Step 4: Verify

Test your new command:

# Verify it works
amc --profile your-profile-name --help

# Test with your configuration
amc --profile your-profile-name --config-file your-config.yaml

What Changed in v0.1.0

Bug Fixes (all verified with tests):

  1. โœ… Time period parsing now correctly calculates previous month
  2. โœ… Year calculation for leap years uses actual cost data year
  3. โœ… Difference calculations show signed values (negative = savings)
  4. โœ… Percentage calculations handle zero baseline correctly
  5. โœ… Configuration validation with clear error messages
  6. โœ… Improved logging when analysis file cannot be generated

Performance Improvements:

  1. โšก BU mode API calls reduced from 2 to 1 (50% reduction)
  2. โšก Optimized sorting algorithms
  3. โšก Faster Excel generation

Security Enhancements:

  1. ๐Ÿ”’ Required --profile argument (no hardcoded defaults)
  2. ๐Ÿ”’ Comprehensive input validation
  3. ๐Ÿ”’ Safe YAML loading (yaml.safe_load)
  4. ๐Ÿ”’ No hardcoded credentials
  5. ๐Ÿ”’ Secure error messages

Code Quality:

  1. ๐Ÿ“ 93% test coverage (226 tests)
  2. ๐Ÿ“ Comprehensive docstrings
  3. ๐Ÿ“ Named constants instead of magic values
  4. ๐Ÿ“ Extracted helper functions
  5. ๐Ÿ“ Improved code organization

Documentation:

  1. ๐Ÿ“š Updated README (this file)
  2. ๐Ÿ“š Testing guide (TESTING.md)
  3. ๐Ÿ“š Security review (SECURITY_REVIEW.md)
  4. ๐Ÿ“š Detailed test documentation (tests/README.md)

Benefits of Upgrading

  • More Secure: Required authentication profile
  • More Reliable: Bug fixes and comprehensive tests
  • Better Performance: Optimized API calls and algorithms
  • Better Documented: Clear documentation and examples
  • Better Maintained: Well-organized, testable code

Testing

The project has comprehensive test coverage. See TESTING.md for details.

Quick Test Run

# Run all tests
tox

# Run tests for specific Python version
tox -e py312

# View coverage report
tox -e py312
open htmlcov/index.html

Test Statistics

  • Total Tests: 226 (all passing โœ…)
  • Coverage: 93% overall, 100% core business logic (runmodes, calculators)
  • Execution Time: < 2 seconds
  • Test Types: Unit tests (200+) + Integration tests (17) + End-to-End tests (7)

See tests/README.md for detailed test documentation.

Security

The application follows security best practices:

  • โœ… No hardcoded credentials
  • โœ… Safe YAML loading (yaml.safe_load)
  • โœ… Comprehensive input validation
  • โœ… No code injection vulnerabilities
  • โœ… Secure dependency versions
  • โœ… Proper error handling

See SECURITY_REVIEW.md for detailed security analysis.

Contributing

Contributions are welcome! Please ensure:

  1. Tests pass: Run tox before submitting
  2. Code is formatted: Run ruff format .
  3. Linting passes: Run ruff check .
  4. Documentation updated: Update README if adding features
  5. Security: No new vulnerabilities introduced

API Documentation

For developers working with the codebase, see API_REFERENCE.md for detailed API documentation including:

  • Function signatures and parameters
  • Module organization
  • Usage examples
  • Type hints and return values

Release Process

For maintainers, see RELEASE_WORKFLOW.md for detailed instructions on:

  • Creating releases with semantic versioning
  • Automated changelog generation
  • Dependency management
  • Publishing to PyPI

Development Setup

# Clone the repository
git clone https://github.com/whoDoneItAgain/aws-monthly-costs.git
cd aws-monthly-costs

# Install in development mode
pip install -e .

# Install development dependencies
pip install tox pytest pytest-cov ruff

# Run tests
tox

# Run linting
ruff check .

# Format code
ruff format .

License

See LICENSE.md for license information.

Changelog

For a complete changelog, see CHANGELOG.md.

Version 0.1.2 (Current)

See CHANGELOG.md for recent updates.

Version 0.1.0 (2026-01-02)

Breaking Changes:

  • --profile argument now required (previously optional)
  • --include-ss renamed to --include-shared-services

Bug Fixes:

  • Fixed time period parsing for previous month calculation
  • Fixed year calculation for leap year handling in historical data
  • Fixed difference calculations (now shows signed values)
  • Fixed percentage calculations for zero baseline edge case
  • Added comprehensive configuration validation

Performance:

  • Reduced BU mode API calls from 2 to 1 (50% reduction)
  • Optimized sorting algorithms
  • Improved Excel generation performance

Testing:

  • Added 112 comprehensive tests (100% coverage on core logic)
  • Added integration tests
  • Added edge case tests (leap years, year boundaries, etc.)

Documentation:

  • Complete README rewrite with examples
  • Added troubleshooting guide
  • Added migration guide
  • Added architecture overview
  • Added security review documentation

Security:

  • CodeQL security scan: 0 alerts
  • No vulnerable dependencies
  • Comprehensive security review completed

See AGENT_HANDOFF.md and SECURITY_REVIEW.md for detailed change logs and security analysis.

Acknowledgments

This project was comprehensively refactored and tested by specialized agents:

  • Refactoring-Expert Agent: Code quality improvements
  • Bug-Hunter Agent: Fixed 7 critical bugs
  • Security-Analyzer Agent: Security review and hardening
  • Performance-Optimizer Agent: Performance optimizations
  • Test-Generator Agent: Comprehensive test suite (226 tests)
  • Documentation-Writer Agent: Documentation updates

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

aws_monthly_costs-0.2.0.tar.gz (73.2 kB view details)

Uploaded Source

Built Distribution

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

aws_monthly_costs-0.2.0-py3-none-any.whl (48.8 kB view details)

Uploaded Python 3

File details

Details for the file aws_monthly_costs-0.2.0.tar.gz.

File metadata

  • Download URL: aws_monthly_costs-0.2.0.tar.gz
  • Upload date:
  • Size: 73.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aws_monthly_costs-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a7bb6dae74c7c1dbc8c08e240efad3bc09ab785e2da26db7b50292b590d5a575
MD5 a280be24d4b7c96547ef8401903157cf
BLAKE2b-256 f5f0e193342b64361e52d9780aa8fd65c1013b99e997d191b68b2336036df81b

See more details on using hashes here.

Provenance

The following attestation bundles were made for aws_monthly_costs-0.2.0.tar.gz:

Publisher: pypi.yaml on whoDoneItAgain/aws-monthly-costs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aws_monthly_costs-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_monthly_costs-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2369a0ec22d20ac156ed65c6b1a70914b015c5362a874d66adb59d407d76a19
MD5 8cafa6ae741895a1ba868e013d0d17a8
BLAKE2b-256 1fb130f446a36a6b628bb8ea4043ec821a4618de9e42f6c30a8ea5c56d8feb4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for aws_monthly_costs-0.2.0-py3-none-any.whl:

Publisher: pypi.yaml on whoDoneItAgain/aws-monthly-costs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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