AWS Expect
Declarative, Pythonic waiters for AWS services using boto3.
Wait for S3 objects, DynamoDB items/tables, SQS messages/events, and Lambda functions to reach an expected state — with content matching, stop_when predicates for early abort, structured Expected:/Actual: error messages, and parallel execution via expect_all / expect_any.
Features
- Declarative syntax:
expect_s3(obj).to_exist(timeout=30) - Content matching: Wait for S3 body JSON or DynamoDB item attributes to match expected values
- Smart polling:
stop_whenpredicates abort early when further polling is pointless; return astr/dictinstead ofTrueto attach a stop reason - Richer errors: Structured
Expected:/Actual:sections in timeout error messages - Native boto3 waiters: Uses AWS's built-in waiter infrastructure where available
- Testing-friendly: Perfect for integration tests and CI/CD pipelines
- Resource-based: Works with boto3 resource objects (S3, DynamoDB, SQS) and client (Lambda)
- Flexible timeouts: Configure both timeout and poll intervals
- Parallel waiting:
expect_all()/expect_any()run multiple expectations concurrently, accepting both plain callables and(fn, *args)tuples - Zero-boilerplate tuples:
(fn, *args)tuples eliminatelambda:wrappers at call sites; trailing dict is unpacked as**kwargs
Installation
pip install aws-expect
Or with uv:
uv add aws-expect
Quick Start
S3 Object Waiting
import boto3
from aws_expect import expect_s3
s3 = boto3.resource("s3")
obj = s3.Object("my-bucket", "report.csv")
metadata = expect_s3(obj).to_exist(timeout=30, poll_interval=5)
print(f"Object exists! Size: {metadata['ContentLength']} bytes")
expect_s3(obj).to_not_exist(timeout=10, poll_interval=2)
# Wait for object body to be valid JSON that deep-matches expected content
body = expect_s3(obj).to_have_content({"status": "shipped"}, timeout=30)
# Assert object body does NOT match after a delay
expect_s3(obj).to_not_have_content({"status": "cancelled"}, delay=5)
# Abort early with stop_when predicate (True stops with no reason)
body = expect_s3(obj).to_exist(
entries={"status": "shipped"},
stop_when=lambda state: state.get("status") == "cancelled",
timeout=60,
)
# A str (or dict) return becomes StopConditionMetError.stop_reason
body = expect_s3(obj).to_exist(
entries={"status": "shipped"},
stop_when=lambda state: (
f"status is {state['status']}"
if state.get("status") == "failed"
else False
),
timeout=60,
)
DynamoDB Item Waiting
import boto3
from aws_expect import expect_dynamodb_item
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table("orders")
item = expect_dynamodb_item(table).to_exist(
key={"pk": "order-123"},
entries={"status": "shipped"},
timeout=60,
poll_interval=5,
)
expect_dynamodb_item(table).to_not_exist(key={"pk": "order-123"}, timeout=10)
# Wait for a timestamp field to be close to a target datetime
from datetime import datetime, timedelta, timezone
item = expect_dynamodb_item(table).to_have_datetime_close_to(
key={"pk": "event-1"},
field="created_at",
delta=timedelta(seconds=30),
expected=datetime(2025, 1, 1, tzinfo=timezone.utc),
timeout=10,
)
# Defaults to now(UTC) when expected is omitted
item = expect_dynamodb_item(table).to_have_datetime_close_to(
key={"pk": "event-1"},
field="created_at",
delta=timedelta(minutes=5),
timeout=10,
)
DynamoDB Table Waiting
from aws_expect import expect_dynamodb_table
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table("orders")
description = expect_dynamodb_table(table).to_exist(timeout=30)
expect_dynamodb_table(table).to_not_exist(timeout=30)
# Wait for table to be empty (no items)
expect_dynamodb_table(table).to_be_empty(timeout=30)
# Wait for table to contain at least one item
expect_dynamodb_table(table).to_be_not_empty(timeout=30)
# Scan table for an item matching entries
item = expect_dynamodb_table(table).to_find_item(
entries={"status": "pending"},
timeout=30,
)
# Assert no matching item exists after a delay
expect_dynamodb_table(table).to_not_find_item({"status": "cancelled"}, delay=5)
# Abort scan early with stop_when predicate (True stops with no reason)
item = expect_dynamodb_table(table).to_find_item(
entries={"status": "pending"},
stop_when=lambda item: item.get("status") == "failed",
timeout=60,
)
# A dict (or str) return becomes StopConditionMetError.stop_reason
item = expect_dynamodb_table(table).to_find_item(
entries={"status": "pending"},
stop_when=lambda item: (
{"error": item["error"]} if "error" in item else False
),
timeout=60,
)
SQS Message Waiting
import boto3
from aws_expect import expect_sqs
sqs = boto3.resource("sqs")
queue = sqs.Queue("https://sqs.us-east-1.amazonaws.com/123456789/my-queue")
# Wait for a plain-text message (non-destructive)
msg = expect_sqs(queue).to_have_message("order-confirmed", timeout=30)
# Wait and consume (delete) the matching message
msg = expect_sqs(queue).to_consume_message("order-confirmed", timeout=30)
# Assert message is absent after a delay
expect_sqs(queue).to_not_have_message("order-confirmed", delay=5)
SQS JSON Event Waiting
# Wait for a JSON message that deep-matches the expected event (non-destructive)
msg = expect_sqs(queue).to_have_event({"type": "ORDER_CREATED", "orderId": "123"}, timeout=30)
# Wait and consume (delete) the matching event
msg = expect_sqs(queue).to_consume_event({"type": "ORDER_CREATED"}, timeout=30)
# Assert no matching event is present after a delay
expect_sqs(queue).to_not_have_event({"type": "ORDER_CREATED"}, delay=5)
Lambda Function Waiting
import boto3
from aws_expect import expect_lambda
lambda_client = boto3.client("lambda")
# Wait for function to exist / be deleted
response = expect_lambda(lambda_client).to_exist("my-function", timeout=30)
expect_lambda(lambda_client).to_not_exist("my-function", timeout=30)
# Wait for function to reach Active state after deployment
response = expect_lambda(lambda_client).to_be_active("my-function", timeout=60)
# Wait for a function update to complete
response = expect_lambda(lambda_client).to_be_updated("my-function", timeout=60)
# Wait until the function can be invoked and returns expected output
payload = expect_lambda(lambda_client).to_be_invocable(
"my-function",
payload={"key": "value"},
entries={"statusCode": 200},
timeout=30,
)
# Invoke once and assert the response (not a waiter — raises immediately on mismatch)
from aws_expect import LambdaResponseMismatchError
result = expect_lambda(lambda_client).to_respond_with(
"my-function",
status_code=200,
expected_payload={"message": "hello"},
request_payload={"key": "value"},
)
Parallel Waiting
from aws_expect import expect_all, expect_s3, expect_dynamodb_item
# Wait for ALL expectations to succeed (raises if any times out)
results = expect_all([
lambda: expect_s3(obj).to_exist(timeout=30),
lambda: expect_dynamodb_item(table).to_exist(key={"pk": "order-123"}, timeout=30),
])
# Wait for the FIRST expectation to succeed (returns its result)
from aws_expect import expect_any, expect_dynamodb_item
result = expect_any([
lambda: expect_dynamodb_item(table_a).to_exist(key={"pk": "u1"}, timeout=30),
lambda: expect_dynamodb_item(table_b).to_exist(key={"pk": "u1"}, timeout=30),
])
# Tuple form — pass (callable, *args) to skip lambda: boilerplate.
# Trailing dict is unpacked as **kwargs.
results = expect_all([
(expect_dynamodb_item(table_a).to_exist, {"pk": "a"}, 30, 1),
(expect_dynamodb_item(table_b).to_exist, {"key": {"pk": "b"}, "timeout": 30}),
])
Catching Any Timeout
All service-specific exceptions inherit from WaitTimeoutError:
from aws_expect import WaitTimeoutError
try:
expect_s3(obj).to_exist(timeout=30)
except WaitTimeoutError:
print("Timed out waiting for resource")
API Reference
Factory Functions
| Function | Description |
|---|---|
expect_s3(s3_object) |
Creates S3ObjectExpectation |
expect_dynamodb_item(table) |
Creates DynamoDBItemExpectation |
expect_dynamodb_table(table) |
Creates DynamoDBTableExpectation |
expect_sqs(queue) |
Creates SQSQueueExpectation |
expect_lambda(lambda_client) |
Creates LambdaFunctionExpectation |
expect_all(expectations) |
Runs expectations concurrently; accepts callables or (fn, *args) tuples; returns all results or raises |
expect_any(expectations) |
Runs expectations concurrently; accepts callables or (fn, *args) tuples; returns first to succeed |
S3 (S3ObjectExpectation)
| Method | Description |
|---|---|
to_exist(timeout, poll_interval, entries, *, stop_when) |
Wait for object to exist; with entries, shallow subset-match body JSON (top-level keys only); supports stop_when |
to_not_exist(timeout, poll_interval) |
Wait for object to be deleted |
to_not_appear(timeout, poll_interval) |
Assert object does not appear within timeout |
to_have_content(entries, timeout, poll_interval) |
Wait until object body is valid JSON deep-matching entries (recursive subset) |
to_not_have_content(entries, delay) |
Assert object body does not deep-match entries after delay |
DynamoDB Item (DynamoDBItemExpectation)
| Method | Description |
|---|---|
to_exist(key, timeout, poll_interval, entries, *, stop_when) |
Wait for item to exist; optionally match attribute entries and abort early via stop_when |
to_not_exist(key, timeout, poll_interval) |
Wait for item to be deleted |
to_have_numeric_value_close_to(key, field, value, delta, timeout, poll_interval) |
Wait for a numeric field to be within delta of value |
to_have_datetime_close_to(key, field, delta, expected, timeout, poll_interval) |
Wait for a timestamp field (epoch or ISO 8601) to be within delta of expected (defaults to now(UTC)) |
DynamoDB Table (DynamoDBTableExpectation)
| Method | Description |
|---|---|
to_exist(timeout, poll_interval) |
Wait for table to exist (Active state) |
to_not_exist(timeout, poll_interval) |
Wait for table to be deleted |
to_be_empty(timeout, poll_interval) |
Wait for table to exist, be Active, and contain no items |
to_be_not_empty(timeout, poll_interval) |
Wait for table to exist, be Active, and contain at least one item |
to_find_item(entries, timeout, poll_interval, *, stop_when) |
Scan table until at least one item subset-matches entries; abort via stop_when |
to_not_find_item(entries, delay) |
Assert no item matches entries after delay |
SQS (SQSQueueExpectation)
| Method | Description |
|---|---|
to_have_message(body, timeout, poll_interval) |
Wait for exact-body message (non-destructive) |
to_consume_message(body, timeout, poll_interval) |
Wait and delete matching message |
to_not_have_message(body, delay) |
Assert message absent after delay |
to_have_event(event, timeout, poll_interval) |
Wait for JSON subset match (non-destructive) |
to_consume_event(event, timeout, poll_interval) |
Wait and delete matching JSON event |
to_not_have_event(event, delay) |
Assert JSON event absent after delay |
Lambda (LambdaFunctionExpectation)
| Method | Description |
|---|---|
to_exist(function_name, timeout, poll_interval) |
Wait for function to exist |
to_not_exist(function_name, timeout, poll_interval) |
Wait for function to be deleted |
to_be_active(function_name, timeout, poll_interval) |
Wait for State == "Active" |
to_be_updated(function_name, timeout, poll_interval) |
Wait for LastUpdateStatus == "Successful" |
to_be_invocable(function_name, timeout, poll_interval, payload, entries) |
Wait until invocation succeeds; optionally match response payload entries |
to_respond_with(function_name, status_code, expected_payload, request_payload) |
Invoke once and assert statusCode and/or JSON body (not a waiter) |
Exceptions
All timeout exceptions inherit from WaitTimeoutError:
| Exception | Raised by |
|---|---|
S3WaitTimeoutError |
S3 existence methods (no entries) |
S3EntriesWaitTimeoutError |
to_exist(entries=...) (subclass of S3WaitTimeoutError) |
S3ContentWaitTimeoutError |
to_have_content |
S3UnexpectedContentError |
to_not_have_content (not a timeout) |
DynamoDBWaitTimeoutError |
DynamoDB methods |
DynamoDBFindItemTimeoutError |
to_find_item |
DynamoDBUnexpectedItemError |
to_not_find_item (not a timeout) |
DynamoDBNonNumericFieldError |
to_have_numeric_value_close_to (not a timeout) |
DynamoDBInvalidTimestampError |
to_have_datetime_close_to (not a timeout) |
SQSWaitTimeoutError |
SQS string-body methods |
SQSEventWaitTimeoutError |
SQS JSON event methods |
SQSUnexpectedMessageError |
to_not_have_message (not a timeout) |
SQSUnexpectedEventError |
to_not_have_event (not a timeout) |
LambdaWaitTimeoutError |
Lambda methods |
LambdaInvocableTimeoutError |
to_be_invocable (with entries) |
LambdaResponseMismatchError |
to_respond_with (not a timeout) |
StopConditionMetError |
stop_when predicate returns a truthy value — True, or a str/dict reason (not a timeout) |
StopConditionError |
stop_when predicate raises an exception (not a timeout) |
AggregateWaitTimeoutError |
expect_all, expect_any |
Development
Setup
git clone https://github.com/PhishStick-hub/aws-expect
cd aws-expect
uv sync --all-groups
Running Tests
Tests use testcontainers and LocalStack for real AWS API simulation:
docker info
uv run pytest tests/ -v
License
MIT License - see LICENSE file for details.
Author
Ivan Shcherbenko
Metadata
Release files for aws-expect 6.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aws_expect-6.0.0.tar.gz | 82.3 kB | With provenance | Details for aws_expect-6.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aws_expect-6.0.0-py3-none-any.whl | Python 3 | none | any | Details for aws_expect-6.0.0-py3-none-any.whl |
Total release size: 112.4 kB
Release files / aws_expect-6.0.0.tar.gz
| Download URL | aws_expect-6.0.0.tar.gz |
|---|---|
| Size | 82.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a71f16b7f6f66b36191f32dedb58f70bffce3ce85ba4b9ad15430d1e45b48f7
|
|
BLAKE2b-256 checksum How to use checksums |
d55c91e34aaa8dce3dac5ca4909131b8dca8165fe4b3f7ecec1ccd1780706596
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 19, 2026.
Transparency logRelease files / aws_expect-6.0.0-py3-none-any.whl
| Download URL | aws_expect-6.0.0-py3-none-any.whl |
|---|---|
| Size | 30.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9899745e73b4fd2d2eaa8fa7cd04a2aaaf62682b77e51d9fb3794fdaadfa1464
|
|
BLAKE2b-256 checksum How to use checksums |
79e45d1e71f615b91acc944814fdcf98004963e7eace7f5937a548abc4c45109
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 19, 2026.
Transparency logSecurity for aws-expect 6.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for aws_expect-6.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.