Skip to main content

Lightweight Python library with AWS and other general purpose classes.

Project description

Need Help? Contact Us PyPI Version Documentation Status Latest Release AWS Services Python Versions License

Lightweight Python library with AWS and other general purpose classes.

Requirements

  • Python 3.10+

  • Linux or macOS (Windows is not supported)

Installation

pip install infrahouse-core

Features

AWS Classes

  • EC2Instance - Manage EC2 instances with SSM command execution support

  • ASGInstance - EC2 instance within an AutoScaling Group (lifecycle state, protection, health)

  • ASG - AutoScaling Group lifecycle management (instance refresh, lifecycle hooks)

  • DynamoDBTable - DynamoDB operations with distributed locking support

  • Route53 Zone - DNS record management (add/delete A records)

  • Secret - AWS Secrets Manager operations (create, read, update, delete)

  • AWS Session Management - SSO login, role assumption, credential handling via get_session(), get_client(), get_resource() helpers

GitHub Integration

  • GitHubActions - Manage self-hosted GitHub Actions runners

  • GitHubActionsRunner - Query runner status, labels, and metadata

  • Token generation from GitHub App credentials stored in AWS Secrets Manager

Utilities

  • Input Validation - Validators for AWS resource identifiers (instance IDs, ARNs, regions, DNS names)

  • Timeout - Context manager for enforcing execution time limits (POSIX only)

  • Filesystem - Secure permission management (ensure_permissions())

  • Logging - Configurable logging setup with stdout/stderr separation

Usage Examples

EC2 Instance with SSM Command Execution

from infrahouse_core.aws.ec2_instance import EC2Instance

# Connect to an instance (optionally assume a role for cross-account access)
instance = EC2Instance(
    instance_id="i-0123456789abcdef0",
    region="us-east-1",
    role_arn="arn:aws:iam::123456789012:role/MyRole"  # optional
)

# Execute a command via SSM
exit_code, stdout, stderr = instance.execute_command("hostname")

# Access instance properties
print(instance.private_ip)
print(instance.hostname)
print(instance.tags)

DynamoDB Distributed Lock

from infrahouse_core.aws.dynamodb import DynamoDBTable

table = DynamoDBTable("my-lock-table", region="us-east-1")

with table.lock("my-resource", timeout=30):
    # Critical section - only one process can hold this lock
    do_exclusive_work()

Route53 DNS Management

from infrahouse_core.aws.route53.zone import Zone

zone = Zone(zone_name="example.com")

# Add an A record
zone.add_record("myhost", "10.0.0.1", ttl=300)

# Delete an A record
zone.delete_record("myhost", "10.0.0.1")

Secrets Manager

from infrahouse_core.aws.secretsmanager import Secret

# Read a secret
secret = Secret("my-app/api-key", region="us-east-1")
print(secret.value)  # Returns dict if JSON, else string

# Create or update a secret
secret.ensure_present({"username": "admin", "password": "secret123"})

# Cross-account access
secret = Secret(
    "prod/database-creds",
    role_arn="arn:aws:iam::123456789012:role/SecretsReader"
)

Cross-Account AWS Access

from infrahouse_core.aws import get_client, get_session

# Get a client with assumed role
ec2 = get_client(
    "ec2",
    role_arn="arn:aws:iam::123456789012:role/CrossAccountRole",
    region="us-west-2"
)

# Or get a session for multiple clients
session = get_session(role_arn="arn:aws:iam::123456789012:role/MyRole")
ec2 = session.client("ec2")
s3 = session.client("s3")

GitHub Actions Runner Management

from infrahouse_core.github import GitHubActions, GitHubAuth

github = GitHubAuth(token="ghp_...", org="my-org")
actions = GitHubActions(github)

# List all runners
for runner in actions.runners:
    print(f"{runner.name}: {runner.status}")

# Find runners by label
runners = actions.find_runners_by_label("self-hosted")

Contributing

Contributions are welcome! Please see CONTRIBUTING.rst for guidelines.

License

Apache Software License 2.0. See LICENSE for details.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

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

infrahouse_core-0.22.0.tar.gz (80.8 kB view details)

Uploaded Source

Built Distribution

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

infrahouse_core-0.22.0-py3-none-any.whl (63.7 kB view details)

Uploaded Python 3

File details

Details for the file infrahouse_core-0.22.0.tar.gz.

File metadata

  • Download URL: infrahouse_core-0.22.0.tar.gz
  • Upload date:
  • Size: 80.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.11

File hashes

Hashes for infrahouse_core-0.22.0.tar.gz
Algorithm Hash digest
SHA256 aeccbf8525c372d2f968a3bf112097a9a78207d46501026bd2ccc5ccfbf4db0d
MD5 6f30ee7dc661ba21ce762f37253a9bd5
BLAKE2b-256 091a770ece773dab920238c3099f0f59f1daacc37771c122495ee6353d0e2254

See more details on using hashes here.

File details

Details for the file infrahouse_core-0.22.0-py3-none-any.whl.

File metadata

File hashes

Hashes for infrahouse_core-0.22.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e1449c4e36c7f8609b5d84a3a0b4cc63b08193358add1bec95b98a4af5751bb6
MD5 6f78977e8a51276abbeb0205db09d198
BLAKE2b-256 6932433aee12dbe9b72bda222b6e2016d03ccb69f8b4fb060d6eeca38b703eb7

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