Skip to main content

A utility library for common AWS services

Project description


๐Ÿš€ aws-util

A comprehensive Python utility library wrapping 100+ AWS services with sync/async parity, Pydantic models, and production-grade error handling.

CI Coverage Lint Test Mutation PyPI Python License


๐Ÿ“‹ Table of Contents


โœจ Features

  • ๐ŸŒ 135 Service Modules โ€” Typed wrappers for S3, SQS, DynamoDB, Lambda, Bedrock, ECS, and 100+ more AWS services with 7,300+ method wrappers
  • โšก Full Async Parity โ€” Every sync function has a native async def counterpart in aws_util.aio.* using a custom aiohttp engine (no monkey-patching)
  • ๐Ÿ›ก๏ธ Structured Exception Hierarchy โ€” AwsThrottlingError, AwsNotFoundError, AwsPermissionError, etc. replace generic RuntimeError while staying backward-compatible
  • ๐Ÿ“ฆ Pydantic Result Models โ€” Every API response is returned as an immutable BaseModel, not a raw dict
  • ๐Ÿ”„ TTL Client Cache โ€” Bounded LRU cache (64 entries, 15-min TTL) auto-rotates STS credentials in long-running processes
  • ๐Ÿ”Œ Multi-Service Orchestration โ€” Pre-built modules for blue/green deployments, data lake management, cross-account operations, disaster recovery, and CI/CD pipelines
  • ๐Ÿ› ๏ธ Lambda Middleware โ€” Idempotency, batch processing, timeout guards, cold-start tracking, and feature flags out of the box
  • ๐Ÿ” Security & Compliance โ€” Least-privilege analysis, secret rotation, data masking, VPC auditing, WAF management, and compliance snapshots
  • ๐Ÿ“Š Observability โ€” Structured logging, X-Ray tracing, EMF metrics, CloudWatch alarms, and automated dashboard generation

๐Ÿ—๏ธ Architecture

graph TB
    subgraph App["๐Ÿ–ฅ๏ธ Your Application"]
        Sync["Sync API<br/>aws_util.*"]
        Async["Async API<br/>aws_util.aio.*"]
    end

    subgraph Core["โš™๏ธ Core Layer"]
        Client["_client.py<br/>TTL LRU Cache"]
        Engine["aio/_engine.py<br/>aiohttp Transport"]
        Errors["exceptions.py<br/>Error Hierarchy"]
    end

    subgraph Services["โ˜๏ธ AWS Services (135 modules)"]
        S3["S3 ยท SQS ยท SNS"]
        DB["DynamoDB ยท RDS ยท ElastiCache"]
        Compute["Lambda ยท ECS ยท EKS ยท Batch"]
        AI["Bedrock ยท SageMaker ยท Rekognition"]
        Security["IAM ยท KMS ยท Secrets Manager"]
        More["+ 100 more services"]
    end

    subgraph Orchestration["๐Ÿ”— Multi-Service Orchestration"]
        Deploy["Deployment & Blue/Green"]
        DataLake["Data Lake & ETL"]
        Resilience["Resilience & Circuit Breaker"]
        Observe["Observability & Monitoring"]
    end

    Sync -->|boto3| Client
    Async -->|aiohttp + SigV4| Engine
    Client --> Services
    Engine --> Services
    Errors -.->|classifies| Services
    Services --> Orchestration

๐Ÿ“ Project Structure

๐Ÿ“ฆ aws-util/
โ”œโ”€โ”€ ๐Ÿ“ src/aws_util/              # 138 sync modules
โ”‚   โ”œโ”€โ”€ ๐Ÿ”‘ __init__.py            # Top-level convenience imports
โ”‚   โ”œโ”€โ”€ โš™๏ธ _client.py             # TTL-aware boto3 client factory
โ”‚   โ”œโ”€โ”€ ๐Ÿšจ exceptions.py          # Structured error hierarchy
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ aio/                   # 137 async counterparts
โ”‚   โ”‚   โ”œโ”€โ”€ โš™๏ธ _engine.py         # Native aiohttp async engine
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ *.py               # One async module per service
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ s3.py                   # S3 operations
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ dynamodb.py             # DynamoDB operations
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ lambda_.py              # Lambda management
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ bedrock.py              # Bedrock AI services
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ blue_green.py           # Blue/green deployments
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ data_lake.py            # Data lake management
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ observability.py        # Monitoring & logging
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ ... (125+ more)        # All other service modules
โ”œโ”€โ”€ ๐Ÿ“ tests/                      # 276 test files, 100% coverage
โ”œโ”€โ”€ ๐Ÿ“ .github/workflows/          # 20 CI/CD workflows
โ”œโ”€โ”€ โš™๏ธ pyproject.toml              # Build config & task runner
โ”œโ”€โ”€ โš™๏ธ Pipfile                     # Dependency management
โ””โ”€โ”€ ๐Ÿ“– README.md
graph LR
    Root["๐Ÿ“ฆ aws-util"] --> Src["๐Ÿ“ src/aws_util"]
    Root --> Tests["๐Ÿงช tests (276 files)"]
    Root --> GH["๐Ÿ“ .github/workflows"]
    Src --> SyncMods["๐Ÿ“„ 135 sync modules"]
    Src --> AIO["๐Ÿ“ aio/"]
    AIO --> AsyncMods["๐Ÿ“„ 137 async modules"]
    AIO --> Engine["โš™๏ธ _engine.py"]
    SyncMods -->|"1:1 parity"| AsyncMods

โš™๏ธ Prerequisites

Before you begin, make sure you have the following installed:

Tool Version Install
Python โ‰ฅ 3.10 python.org
pip โ‰ฅ 21.x Comes with Python
pipenv Latest pip install pipenv
AWS CLI โ‰ฅ 2.x aws.amazon.com/cli
taskipy Latest Installed via dev deps

๐Ÿ’ก Tip: Configure AWS credentials via aws configure or environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION).


๐Ÿš€ Quick Start

1. Clone the repository

git clone https://github.com/Masrik-Dahir/aws-util-python.git
cd aws-util-python

2. Install dependencies

pip install -e .[dev]
# Or with pipenv:
PIPENV_IGNORE_VIRTUALENVS=1 pipenv install --dev

3. Install from PyPI (library usage)

pip install aws-util

4. Use it โ€” Sync

from aws_util.s3 import upload_file, download_bytes, list_objects
from aws_util.dynamodb import get_item, put_item
from aws_util.sqs import send_message, receive_messages

# Upload a file to S3
upload_file("my-bucket", "data/report.csv", "/tmp/report.csv")

# Query DynamoDB
item = get_item("users-table", {"pk": "user#123"})

# Send an SQS message
send_message("my-queue", {"event": "order.placed", "id": "abc"})

5. Use it โ€” Async

from aws_util.aio.s3 import upload_file, download_bytes
from aws_util.aio.dynamodb import get_item, put_item

async def main():
    await upload_file("my-bucket", "key.csv", "/tmp/data.csv")
    item = await get_item("users-table", {"pk": "user#123"})

๐Ÿ“– Usage

Placeholder Resolution (SSM + Secrets Manager)

from aws_util import retrieve

# Resolves SSM parameters and Secrets Manager secrets
db_url = retrieve("{{ssm:/prod/db/url}}")
api_key = retrieve("{{secret:prod/api-key}}")

Multi-Service Orchestration

from aws_util.deployer import deploy_lambda_with_config, deploy_ecs_from_ecr
from aws_util.data_pipeline import run_glue_then_query, export_query_to_s3_json
from aws_util.security_ops import audit_public_s3_buckets, rotate_iam_access_key
from aws_util.blue_green import ecs_blue_green_deployer

Lambda Middleware

from aws_util.lambda_middleware import (
    idempotent_handler, batch_processor, middleware_chain,
    lambda_timeout_guard, cold_start_tracker, lambda_response,
)

Event-Driven Orchestration

from aws_util.event_orchestration import (
    create_eventbridge_rule, saga_orchestrator, fan_out_fan_in,
    create_schedule, run_workflow,
)

Resilience & Error Handling

from aws_util.resilience import circuit_breaker, retry_with_backoff, dlq_monitor_and_alert
from aws_util.exceptions import AwsThrottlingError, AwsNotFoundError

try:
    item = get_item("table", {"pk": "key"})
except AwsNotFoundError:
    print("Resource not found")
except AwsThrottlingError:
    print("Rate limited โ€” retrying")

Observability

from aws_util.observability import (
    StructuredLogger, create_xray_trace, emit_emf_metric,
    create_lambda_alarms, generate_lambda_dashboard,
)

Security & Compliance

from aws_util.security_compliance import (
    least_privilege_analyzer, secret_rotation_orchestrator,
    data_masking_processor, compliance_snapshot,
)

Cost Optimization

from aws_util.cost_optimization import (
    lambda_right_sizer, unused_resource_finder,
    concurrency_optimizer, cost_attribution_tagger,
)

AI/ML Pipelines

from aws_util.ai_ml_pipelines import (
    bedrock_serverless_chain, s3_document_processor,
    image_moderation_pipeline, translation_pipeline,
)

All 135 Service Modules

Click to expand full module list
Category Modules
Storage s3, efs, fsx, storage_gateway
Database dynamodb, rds, rds_data, documentdb, elasticache, memorydb, neptune, neptune_graph, redshift, redshift_data, redshift_serverless, keyspaces, timestream_write, timestream_query
Compute lambda_, ecs, ecr, ec2, eks, batch, app_runner, autoscaling, elastic_beanstalk, emr, emr_containers, emr_serverless, lightsail
Messaging sqs, sns, ses, ses_v2, eventbridge, kinesis, firehose, msk, messaging
AI/ML bedrock, bedrock_agent, bedrock_agent_runtime, comprehend, rekognition, textract, translate, transcribe, polly, personalize, personalize_runtime, forecast, forecast_query, sagemaker_runtime, sagemaker_featurestore_runtime, lex_models, lex_runtime
Security iam, kms, secrets_manager, cognito, cognito_identity, access_analyzer, detective, inspector, macie, security_hub, sso_admin
Networking route53, acm, cloudfront, elbv2, vpc_lattice
Management cloudwatch, cloudtrail, cloudformation, config_service, organizations, health, service_quotas
Developer Tools codebuild, codecommit, codedeploy, codepipeline, codeartifact, codestar_connections
Analytics athena, glue, databrew, quicksight, kinesis_analytics
IoT iot, iot_data, iot_greengrass, iot_sitewise
Media connect, ivs, mediaconvert
Migration dms, transfer
Orchestration stepfunctions, event_orchestration, data_flow_etl, data_pipeline, blue_green, deployer, deployment, disaster_recovery, container_ops, ml_pipeline, networking, cross_account, data_lake, database_migration, credential_rotation, cost_governance, cost_optimization, security_automation, security_compliance, security_ops, infra_automation, resilience, observability, resource_ops, config_loader, config_state, event_patterns, lambda_middleware, api_gateway, notifier, messaging, ai_ml_pipelines, testing_dev
Core _client, exceptions, placeholder, parameter_store, sts

๐Ÿ”ง Configuration

Variable Required Default Description
AWS_ACCESS_KEY_ID โœ… โ€” AWS access key
AWS_SECRET_ACCESS_KEY โœ… โ€” AWS secret key
AWS_DEFAULT_REGION โŒ us-east-1 Default AWS region
AWS_SESSION_TOKEN โŒ โ€” Session token for temporary credentials

The library uses boto3's standard credential chain. Credentials can also come from IAM roles, instance profiles, SSO, or environment variables.


๐Ÿงช Testing

# Run all tests
task test

# Run tests with coverage report
task test-cov

# Run mutation testing
task mutation-test

# Run coverage with 100% enforcement
task coverage

# Lint and format
task lint

# Type checking
task typecheck

# Full pre-release check (lint + test + coverage + typecheck)
task prepare

Test Stats

Metric Value
Test files 276
Coverage target 100%
Async test support asyncio_mode = "auto"
Mocking framework moto (S3, SQS, SNS, DynamoDB, Lambda, and more)

๐Ÿ”„ CI/CD

This project uses 20 GitHub Actions workflows for comprehensive automation.

Workflow Trigger Purpose
ci.yml Push / PR Full lint + test + typecheck pipeline
test.yml Push / PR Run pytest suite
coverage.yml Push / PR Enforce 100% code coverage
mutation.yml Push / PR Mutation testing with pytest-gremlins
lint.yml Push / PR Ruff linting and formatting
typecheck.yml Push / PR mypy static type checking
build.yml Push / PR Build package artifacts
publish.yml Tags / Release Publish to PyPI
codeql.yml Push / PR / Schedule CodeQL security analysis
security-scan.yml Push / PR Security vulnerability scanning
dependency-review.yml PR Review dependency changes
version-check.yml PR Verify version bump
changelog.yml PR Validate changelog entries
pr-size.yml PR Label PRs by size
label-pr.yml PR Auto-label PRs by file paths
release-drafter.yml Push to master Draft release notes
stale.yml Schedule Close stale issues/PRs
lock-threads.yml Schedule Lock old threads
issue-triage.yml Issues Auto-triage new issues
welcome.yml PR / Issue Welcome new contributors

Pipeline Flow

flowchart LR
    PR[Pull Request] --> Lint[๐Ÿ” Lint]
    PR --> Type[๐Ÿ“ Typecheck]
    Lint --> Test[๐Ÿงช Test]
    Type --> Test
    Test --> Cov[๐Ÿ“Š Coverage 100%]
    Test --> Mut[๐Ÿงฌ Mutation]
    Cov --> |merge to master| Build[๐Ÿ“ฆ Build]
    Build --> |tag v*| Publish[๐Ÿš€ PyPI]

All checks must pass before merging. See .github/workflows/ for full configuration.


๐Ÿ“ Changelog

Version Date Highlights
v2.2.7 2026-04-09 Scoped CI to S3 module for faster test runs
v2.2.6 2026-04-08 6,189 new boto3 method wrappers (7,303 total), 7,682 new tests
v2.2.5 2026-04-07 71 new service modules (135 total), covering 100+ AWS services
v2.0.0 2026-03-31 Structured exceptions, native async engine, 64 modules, TTL client cache

See CHANGELOG.md for the full history.


๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feat/amazing-feature
  3. Commit your changes: git commit -m 'feat: add amazing feature'
  4. Push to the branch: git push origin feat/amazing-feature
  5. Open a Pull Request

Development Setup

git clone https://github.com/Masrik-Dahir/aws-util-python.git
cd aws-util-python
pip install -e .[dev]
task prepare   # lint + test + coverage + typecheck

Commit Convention

This project uses Conventional Commits:

Prefix Use for
feat: New features
fix: Bug fixes
docs: Documentation only
chore: Build / tooling changes
test: Adding or fixing tests

Please ensure all tests pass and coverage stays at 100% before opening a PR.


๐Ÿ“„ License

Distributed under the MIT License. See LICENSE for more information.


Made with โค๏ธ by Masrik Dahir

โญ Star this repo if you find it helpful!

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_util-2.2.9.tar.gz (4.0 MB view details)

Uploaded Source

Built Distribution

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

aws_util-2.2.9-py3-none-any.whl (2.5 MB view details)

Uploaded Python 3

File details

Details for the file aws_util-2.2.9.tar.gz.

File metadata

  • Download URL: aws_util-2.2.9.tar.gz
  • Upload date:
  • Size: 4.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aws_util-2.2.9.tar.gz
Algorithm Hash digest
SHA256 1071a8462031d5cf4459f73510291753507a7924d7a594e3a904058fc3218aa8
MD5 9c5699e78ce1d27bfc3d1d6acfd20d3f
BLAKE2b-256 b6e99f0daee6eaf4afbfbf84f04252a8ee86369477ac6701f1ea930663e4b1f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for aws_util-2.2.9.tar.gz:

Publisher: publish.yml on Masrik-Dahir/aws-util-python

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_util-2.2.9-py3-none-any.whl.

File metadata

  • Download URL: aws_util-2.2.9-py3-none-any.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aws_util-2.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 5ad3553279fe60cdf25c1676a2193c1054bc4ddecc73fcc32d22245127a0cb31
MD5 5c747750f4b02935bf3e55f1d75d7236
BLAKE2b-256 190c68a57ea53d01fcb183b03d8bb781a8f7f246a602108380756a481e91e8a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for aws_util-2.2.9-py3-none-any.whl:

Publisher: publish.yml on Masrik-Dahir/aws-util-python

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