Skip to main content

AWS Durable Execution SDK for Python

Build PyPI - Version PyPI - Python Version OpenSSF Scorecard License

Write AWS Lambda durable functions in Python: workflows with checkpointed steps, waits, callbacks, and parallel work.

Install

pip install aws-durable-execution-sdk-python

Quick start

from aws_durable_execution_sdk_python import (
    DurableContext,
    StepContext,
    durable_execution,
    durable_step,
)
from aws_durable_execution_sdk_python.config import Duration


@durable_step
def validate_order(step_ctx: StepContext, order_id: str) -> dict:
    step_ctx.logger.info("Validating order", extra={"order_id": order_id})
    return {"order_id": order_id, "valid": True}


@durable_execution
def handler(event: dict, context: DurableContext) -> dict:
    order_id = event["order_id"]
    validation = context.step(validate_order(order_id))
    if not validation["valid"]:
        return {"status": "rejected", "order_id": order_id}

    # The function stops while it waits, so no Lambda compute is billed.
    context.wait(Duration.from_seconds(5), name="cool-down")
    return {"status": "approved", "order_id": order_id}

@durable_execution makes handler the Lambda handler. Each context.step result is checkpointed. After a wait or a failure, the function runs again from the start, and completed steps return their checkpointed result.

Common uses

Wait for an external system

from aws_durable_execution_sdk_python import DurableContext, durable_execution


def send_approval_request(callback_id: str, context) -> None:
    ...  # Send callback_id to the approver.


@durable_execution
def handler(event: dict, context: DurableContext) -> dict:
    decision = context.wait_for_callback(send_approval_request, name="approval")
    return {"decision": decision}

The approver completes the callback with the Lambda SendDurableExecutionCallbackSuccess API and the callback ID.

Process a list of items

from collections.abc import Sequence

from aws_durable_execution_sdk_python import DurableContext, durable_execution
from aws_durable_execution_sdk_python.config import MapConfig


def resize(ctx: DurableContext, image: str, index: int, images: Sequence[str]) -> str:
    return ctx.step(lambda _: f"small-{image}", name=f"resize-{index}")


@durable_execution
def handler(event: dict, context: DurableContext) -> list[str]:
    batch = context.map(
        event["images"], resize, name="resize", config=MapConfig(max_concurrency=5)
    )
    return batch.get_results()

context.parallel runs a list of different functions the same way.

Group operations in a child context

from aws_durable_execution_sdk_python import (
    DurableContext,
    durable_execution,
    durable_with_child_context,
)
from aws_durable_execution_sdk_python.config import Duration


@durable_with_child_context
def ship(ctx: DurableContext, order_id: str) -> str:
    label = ctx.step(lambda _: f"label-{order_id}", name="label")
    ctx.wait(Duration.from_seconds(1), name="pickup")
    return label


@durable_execution
def handler(event: dict, context: DurableContext) -> str:
    return context.run_in_child_context(ship(event["order_id"]), name="ship")

Call another function

from aws_durable_execution_sdk_python import DurableContext, durable_execution


@durable_execution
def handler(event: dict, context: DurableContext) -> dict:
    payment = context.invoke("process-payment", {"amount": 25}, name="payment")
    return {"charged": payment["charged"]}

The function stops while it waits for the result. The target can be a durable function or a plain Lambda function.

Advanced

Retries and errors

A step retries on failure according to its retry strategy. After the last attempt, the step raises StepError.

from aws_durable_execution_sdk_python import (
    DurableContext,
    StepContext,
    StepError,
    durable_execution,
    durable_step,
)
from aws_durable_execution_sdk_python.config import Duration, StepConfig
from aws_durable_execution_sdk_python.retries import (
    RetryStrategyConfig,
    create_retry_strategy,
)

RETRY = StepConfig(
    retry_strategy=create_retry_strategy(
        RetryStrategyConfig(max_attempts=3, initial_delay=Duration.from_seconds(2))
    )
)


@durable_step
def charge(step_ctx: StepContext, amount: int) -> dict:
    # Call the payment service here. An exception makes the step retry.
    return {"status": "charged", "amount": amount}


@durable_execution
def handler(event: dict, context: DurableContext) -> dict:
    try:
        return context.step(charge(event["amount"]), config=RETRY)
    except StepError as error:
        context.logger.warning("Charge failed", extra={"error": str(error)})
        return {"status": "failed"}

RetryPresets in aws_durable_execution_sdk_python.retries holds ready-made strategies.

Pause after repeated failures (experimental)

A retry decision can pause the durable execution. When the retry strategy returns RetryDecision.retry(delay, pause=True) for a failed attempt, the step saves its normal retry, then the SDK asks Lambda to pause, and the invocation ends. An operator resumes the execution with the Lambda ResumeDurableExecution API, and the next attempt runs.

The built-in strategy pauses after every Nth failed attempt with pause_every. For example, pause_every=5 pauses after attempts 5, 10, 15, and so on:

RETRY_AND_PAUSE = StepConfig(
    retry_strategy=create_retry_strategy(
        RetryStrategyConfig(
            max_attempts=20,
            initial_delay=Duration.from_seconds(60),
            pause_every=5,
        )
    )
)

A custom strategy sets pause itself. This one pauses on attempt 5 only when the error is a PartnerUnavailableError:

def retry_and_pause(error: Exception, attempt: int) -> RetryDecision:
    if attempt >= 20:
        return RetryDecision.no_retry()
    return RetryDecision.retry(
        Duration.from_seconds(60),
        pause=attempt == 5 and isinstance(error, PartnerUnavailableError),
    )


RETRY_AND_PAUSE = StepConfig(retry_strategy=retry_and_pause)
  • pause does not change how many attempts run. When the decision has should_retry=False, the step fails as usual and does not pause.
  • context.step uses pause, including the wait_for_callback submitter. with_retry ignores pause.
  • Only an attempt that raised in the current invocation can pause. An AT_MOST_ONCE_PER_RETRY attempt that was interrupted retries without a pause.
  • The pause applies to the whole execution. A step in a map or parallel branch can still pause the execution after the map or parallel operation has finished. No checkpointed data is lost. Resume the execution to continue.
  • Give the function's execution role lambda:PauseDurableExecution on its own durable executions. If the function uses a customer managed AWS KMS key, the role also needs kms:Decrypt on that key, as the Lambda pause and resume prerequisites require. If the pause call fails, the SDK logs a warning with the error and the step retries as usual. A missing permission is one possible cause.
  • This feature is experimental. It may change or be removed in a future release.

Replay rules

The function runs again from the start after each wait, retry, or resume. So:

  1. Code outside steps must be deterministic. Put timestamps, random values, and API calls in a step.
  2. Do not call durable operations inside a step. Use a child context to group operations.
  3. Return values from steps. A step's changes to variables outside it are lost on replay.
  4. Use context.logger for logs. It does not repeat log lines on replay.

Instrumentation plugins

Set DURABLE_EXECUTION_PLUGINS to load installed plugins at cold start, in order:

DURABLE_EXECUTION_PLUGINS=otel-invocation

You can also pass plugin factories to @durable_execution(plugins=[...]). See docs/plugins.md for the factory contract, the OpenTelemetry views, and trace propagation.

Reference

Feedback and support

License

See the LICENSE file for our project's licensing.

Metadata

Release files for aws-durable-execution-sdk-python 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-durable-execution-sdk-python 3.1.0
File Size Uploaded Provenance Actions
aws_durable_execution_sdk_python-3.1.0.tar.gz 431.3 kB With provenance Details for aws_durable_execution_sdk_python-3.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aws-durable-execution-sdk-python 3.1.0
File Interpreter ABI Platform Actions
aws_durable_execution_sdk_python-3.1.0-py3-none-any.whl Python 3 none any Details for aws_durable_execution_sdk_python-3.1.0-py3-none-any.whl

Total release size: 596.0 kB

Release files / aws_durable_execution_sdk_python-3.1.0.tar.gz

Download URL aws_durable_execution_sdk_python-3.1.0.tar.gz
Size 431.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4e5f1050e6859b0fcc32b7e6d0492ca3d45dbe17c051e93dcea318f1f60bb93a
BLAKE2b-256 checksum
How to use checksums
5756c6a36243968ba6fc3dc63ffe0a7484659a7b1bd5535f18a4e4a98a28ee3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 19, 2026.

Transparency log

Release files / aws_durable_execution_sdk_python-3.1.0-py3-none-any.whl

Download URL aws_durable_execution_sdk_python-3.1.0-py3-none-any.whl
Size 164.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8329612f0e5a518ff54a10f6e418cd9d75bb518bb99377845b19ae15a21c8a9
BLAKE2b-256 checksum
How to use checksums
a39ef8ff0a43c302ea4e7d09646c9c9d068aad9d7471cd76908f086fb0546afe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 19, 2026.

Transparency log

Security for aws-durable-execution-sdk-python 3.1.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.

Select from 2 files

Attestation for aws_durable_execution_sdk_python-3.1.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 Nov 19, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page