Skip to main content

Python SDK for fakecloud — local AWS cloud emulator

Project description

fakecloud

Python SDK for fakecloud — a local AWS cloud emulator.

This package provides async and sync clients for the fakecloud introspection and simulation API (/_fakecloud/* endpoints), letting you inspect sent emails, published messages, Lambda invocations, and more from your tests.

Installation

pip install fakecloud

Quick start

Async

import asyncio
from fakecloud import FakeCloud

async def main():
    async with FakeCloud("http://localhost:4566") as fc:
        # Check server health
        health = await fc.health()
        print(health.status, health.version)

        # List sent SES emails
        emails = await fc.ses.get_emails()
        for email in emails.emails:
            print(f"{email.from_addr} -> {email.to}: {email.subject}")

        # List SNS messages
        messages = await fc.sns.get_messages()
        for msg in messages.messages:
            print(f"{msg.topic_arn}: {msg.message}")

        # Inspect Lambda invocations
        invocations = await fc.lambda_.get_invocations()
        for inv in invocations.invocations:
            print(f"{inv.function_arn}: {inv.payload}")

        # Reset all state between tests
        await fc.reset()

asyncio.run(main())

Sync

from fakecloud import FakeCloudSync

with FakeCloudSync("http://localhost:4566") as fc:
    health = fc.health()
    print(health.status)

    emails = fc.ses.get_emails()
    for email in emails.emails:
        print(email.subject)

API reference

The SDK ships two top-level clients with identical surfaces:

  • FakeCloud — async (await fc.x.y()), context-manager friendly
  • FakeCloudSync — sync (fc.x.y())

Tables below document the async API. Drop the await and use FakeCloudSync for the sync variant; method names and arguments match exactly.

Top-level

Pass base_url (default http://localhost:4566).

Method Description
health() Server health check
reset() Reset all service state
reset_service(service) Reset a single service
create_admin(account_id, user_name) Create an IAM admin user in a specific account
aclose() (async only) Close the underlying httpx.AsyncClient (or use async with)

fc.lambda_

lambda is a Python keyword, so the attribute is lambda_.

Method Description
get_invocations() List recorded Lambda invocations
get_warm_containers() List warm containers
evict_container(function_name) Evict a warm container
download_function_code(account_id, function_name, qualifier_or_latest="latest") Download function-code zip (bytes)
download_layer_content(account_id, layer_name, version) Download layer-version zip (bytes)

fc.rds

Method Description
get_instances() List managed RDS instances
lambda_invoke(req) Invoke a Lambda via the RDS aws_lambda PG extension bridge
s3_import(req) Fetch an S3 object via the RDS aws_s3 extension bridge
s3_export(req) Upload an object via the RDS aws_s3 extension bridge

fc.elasticache

Method Description
get_clusters() List cache clusters
get_replication_groups() List replication groups
get_serverless_caches() List serverless caches
get_elasti_cache_acls() List ElastiCache ACLs

fc.athena

Method Description
get_named_queries() List every named query across workgroups (with last_used_at)

fc.ecr

Method Description
get_repositories() List ECR repositories
get_images(repository_name=None) List images, optionally filtered by repo
get_pull_through_rules() List pull-through cache rules

fc.ecs

Method Description
get_clusters() List ECS clusters
get_tasks(cluster=None, status=None) List tasks, optionally filtered by cluster/status
get_task(task_id) Get a single task
get_task_logs(task_id) Tail captured stdout/stderr for a task
force_stop_task(task_id) Force-stop a running task
mark_task_failed(task_id, req) Mark a task as failed with a given reason
get_events() List ECS service events
get_task_metadata(task_arn) v4 metadata-URI dump for a task by ARN
get_task_credentials(task_id) IAM credentials a running task would see
get_task_metadata_v3(task_id) v3 task metadata document (pass-through dict)
get_task_metadata_v4(task_id) v4 task metadata document (pass-through dict)

fc.elbv2

Method Description
get_load_balancers() List ALBs / NLBs / GWLBs
get_target_groups() List target groups
get_listeners() List listeners
get_rules() List listener rules
flush_access_logs() Force buffered access + connection logs to S3
get_waf_counts() Snapshot WAF-association counts across ALBs

fc.route53

Method Description
set_health_check_status(health_check_id, status, reason=None) Flip a health check (Success/Failure/Timeout/DnsError/InsufficientDataPoints/Unknown)
get_dnssec_material(zone_id) Deterministic DNSSEC KSK material for a zone
sign_dnssec_rrset(zone_id, req) Sign an RRset under the zone's first ACTIVE KSK

fc.ssm

Method Description
set_command_status(command_id, status, account_id=None) Force a stored SendCommand into a given status
fail_command(command_id, req=None) Flip every (or one) invocation on a command to Failed
get_parameter_policy_events(account_id=None) List Parameter Store policy events
inject_session(req) Drop a fake Session Manager record into state

fc.kms

Method Description
get_usage() Snapshot recorded KMS usage events across services

fc.wafv2

Method Description
evaluate(body) Run a synthetic request through the WAFv2 evaluator

fc.cloudfront

Method Description
set_distribution_status(distribution_id, status) Force a distribution into a given status

fc.acm

Method Description
set_certificate_status(arn_or_id, status, reason=None) Flip cert status (ISSUED/FAILED/VALIDATION_TIMED_OUT)
approve_certificate(arn_or_id) Approve a PENDING_VALIDATION cert (EMAIL validation flow)
get_certificate_chain_info(arn_or_id) PEM-block / byte counts for a stored cert + chain

fc.application_autoscaling

Method Description
tick() Force the watcher to evaluate every scaling policy now
scheduled_tick() Force the scheduled-action executor to evaluate every action now

fc.logs

Method Description
inject_anomaly(req) Seed a synthetic anomaly for ListAnomalies/UpdateAnomaly
get_delivery_config() Persisted CloudWatch Logs delivery configurations
get_field_indexes(log_group_name) Parsed Fields from index policies on a log group

fc.organizations

Called as a method on the main client: fc.organizations().

Method Description
get_accounts() List member accounts with lifecycle state, parent OU, tags, attached SCPs

fc.ses

Method Description
get_emails() List all sent emails
simulate_inbound(req) Simulate an inbound email (receipt rules)
get_metrics() Send/bounce/complaint metrics
set_mail_from_status(identity, status) Set MAIL FROM verification status for an identity
get_dkim_public_key(identity) Public DKIM key for an identity
set_sandbox(sandbox) Enable/disable account-level sandbox
get_bounces() List recorded bounces
get_message_insights(message_id) Message insights record for a sent message
get_smtp_submissions() List SMTP-submission events
get_event_destination_deliveries() Deliveries fanned out to event destinations

fc.sns

Method Description
get_messages() List all published messages
get_pending_confirmations() List subscriptions pending confirmation
confirm_subscription(req) Confirm a pending subscription
get_cert_pem() Signing cert as a PEM string
get_sms() List SMS messages accepted by the SNS fake

fc.sqs

Method Description
get_messages() List all messages across queues
tick_expiration() Tick the message-expiration processor
force_dlq(queue_name) Force all messages to the queue's DLQ

fc.events

Method Description
get_history() Get EventBridge event history
fire_rule(req) Fire an EventBridge rule manually

fc.scheduler

Method Description
get_schedules() List scheduler schedules
fire_schedule(group, name) Manually fire a schedule by group/name

fc.glue

Method Description
get_jobs() List Glue jobs
get_job_runs(job_name=None) List job runs, optionally filtered by job

fc.s3

Method Description
get_notifications() List S3 notification events
tick_lifecycle() Tick the lifecycle processor
get_access_points() List S3 access points
get_object_lambda_responses() List recorded Object Lambda responses

fc.dynamodb

Method Description
tick_ttl() Tick the TTL processor

fc.secretsmanager

Method Description
tick_rotation() Tick the rotation scheduler

fc.cognito

Method Description
get_user_codes(pool_id, username) Confirmation codes for a specific user
get_confirmation_codes() List all pending confirmation codes
confirm_user(req) Force-confirm a user
get_tokens() List active tokens
expire_tokens(req) Expire tokens for a pool/user
get_auth_events() List auth events
get_pre_token_gen_invocations() PreTokenGeneration Lambda trigger invocation log
mint_authorization_code(req) Mint an OAuth authorization code
set_compromised_passwords(req) Seed compromised-password records
get_webauthn_credentials() List stored WebAuthn credentials

fc.apigatewayv2

Method Description
get_requests() List recorded HTTP API requests
get_connections() List active WebSocket connections
get_mtls_info(domain_name) mTLS trust-store summary for a custom domain (dict)
ws_url(api_id, stage=None) Build the ws(s):// WebSocket URL for an API + stage

fc.stepfunctions

Method Description
get_executions() List all executions
get_sync_executions() List sync (Express) executions
get_execution_tree(arn) Nested execution tree for a parent execution
enqueue_activity_task(req) Insert a pending task into an activity-worker queue

fc.bedrock

Method Description
get_invocations() List recorded Bedrock runtime invocations
set_model_response(model_id, text) Configure a single canned response for a model
set_response_rules(model_id, rules) Replace prompt-conditional response rules
clear_response_rules(model_id) Clear all prompt-conditional response rules for a model
queue_fault(rule) Queue a fault rule for the next N matching calls
get_faults() List currently queued fault rules
clear_faults() Clear all queued fault rules

fc.bedrock_agent

Method Description
get_agents() List Bedrock Agents (control plane)

fc.bedrock_agent_runtime

Method Description
get_invocations() List Bedrock Agent runtime invocations (data plane)

Testing Bedrock-calling code end-to-end

from fakecloud import FakeCloudSync
from fakecloud.types import BedrockResponseRule, BedrockFaultRule

fc = FakeCloudSync()
model_id = "anthropic.claude-3-haiku-20240307-v1:0"


def test_classifier_branches_on_spam_vs_ham():
    fc.reset()
    fc.bedrock.set_response_rules(
        model_id,
        [
            BedrockResponseRule(prompt_contains="buy now", response='{"label":"spam"}'),
            BedrockResponseRule(prompt_contains=None, response='{"label":"ham"}'),
        ],
    )

    classify("hello friend")           # user code that calls Bedrock
    classify("buy now cheap pills")

    invocations = fc.bedrock.get_invocations().invocations
    assert len(invocations) == 2
    assert "ham" in invocations[0].output
    assert "spam" in invocations[1].output


def test_retries_on_throttling():
    fc.reset()
    fc.bedrock.queue_fault(
        BedrockFaultRule(
            error_type="ThrottlingException",
            message="Rate exceeded",
            http_status=429,
            count=1,  # only the first call faults; the retry succeeds
        )
    )

    classify("hello")

    invocations = fc.bedrock.get_invocations().invocations
    assert len(invocations) == 2
    assert "ThrottlingException" in (invocations[0].error or "")
    assert invocations[1].error is None

Error handling

All methods raise FakeCloudError on non-2xx responses:

from fakecloud.client import FakeCloudError

try:
    await fc.health()
except FakeCloudError as e:
    print(e.status, e.body)

pytest fixture example

import pytest
from fakecloud import FakeCloudSync

@pytest.fixture(autouse=True)
def reset_fakecloud():
    fc = FakeCloudSync()
    fc.reset()
    yield fc
    fc.close()

def test_email_sent(reset_fakecloud):
    # ... your code that sends an email via SES ...
    emails = reset_fakecloud.ses.get_emails()
    assert len(emails.emails) == 1
    assert emails.emails[0].subject == "Welcome"

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

fakecloud-0.15.2.tar.gz (49.5 kB view details)

Uploaded Source

Built Distribution

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

fakecloud-0.15.2-py3-none-any.whl (45.3 kB view details)

Uploaded Python 3

File details

Details for the file fakecloud-0.15.2.tar.gz.

File metadata

  • Download URL: fakecloud-0.15.2.tar.gz
  • Upload date:
  • Size: 49.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for fakecloud-0.15.2.tar.gz
Algorithm Hash digest
SHA256 ce15c2dff72fba8af357abbb53dbbfcb9d74f2914b1e8661a93cc89fc6588ac6
MD5 aba5d255743d967f5836e126b43f3445
BLAKE2b-256 4f701d9b542479ccbe0cb2be69b0c16ee840373bfc42daeb317d20ee38dff969

See more details on using hashes here.

File details

Details for the file fakecloud-0.15.2-py3-none-any.whl.

File metadata

  • Download URL: fakecloud-0.15.2-py3-none-any.whl
  • Upload date:
  • Size: 45.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for fakecloud-0.15.2-py3-none-any.whl
Algorithm Hash digest
SHA256 86a8916332c30f74bebddc4ae677c66e97f9a00410806e4b6465a3b227980e16
MD5 acd6851261aaf23c9eefe7e05e7f01c8
BLAKE2b-256 5207ec2d9245886d578bc6104d6acd9e893ddeebfcf997f55a0d40394c3b3413

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