Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/scripts/js_examples/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,35 @@
# The examples depend on these local workspaces. The root "npm run build"
# also builds the telemetry tools and the VS Code extension, which the harness
# does not need, so the script builds only these, in dependency order.
#
# The list holds both names of the worker package, microvm-worker and
# compute-worker. The harness builds a checkout of any JS ref: main by
# default, or the js_ref input of the workflow. A ref from before the rename
# in aws/aws-durable-execution-sdk-js#1204 has only microvm-worker, and the
# examples of that ref import it. A ref from after the rename has only
# compute-worker. So the list names both, and the build skips the one that
# the checkout does not have. See OPTIONAL_JS_BUILD_WORKSPACES.
JS_BUILD_WORKSPACES = (
"packages/aws-durable-execution-sdk-js",
"packages/aws-durable-execution-sdk-js-testing",
"packages/aws-durable-execution-sdk-js-otel",
"packages/aws-durable-execution-sdk-js-extras",
"packages/aws-durable-execution-sdk-js-microvm-worker",
"packages/aws-durable-execution-sdk-js-compute-worker",
"packages/aws-durable-execution-sdk-js-examples",
)
# Older JS refs predate these packages; their examples do not need them.
# The build skips a workspace in this set when the JS checkout does not have
# it. Older JS refs predate extras, and their examples do not need it. A JS
# ref has at most one of the two worker names, because of the rename above.
# Until aws/aws-durable-execution-sdk-js#1204 merges, JS main still has
# microvm-worker. So removing microvm-worker now would break the default run
# against main. After the merge, it stays so that a run with an older js_ref
# still builds.
OPTIONAL_JS_BUILD_WORKSPACES = frozenset(
{
"packages/aws-durable-execution-sdk-js-extras",
"packages/aws-durable-execution-sdk-js-microvm-worker",
"packages/aws-durable-execution-sdk-js-compute-worker",
}
)
# otel examples export spans to an OpenTelemetry collector. The harness does
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/tests/test_js_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def test_build_produces_example_workspace_dependencies(
testing = "packages/aws-durable-execution-sdk-js-testing"
otel = "packages/aws-durable-execution-sdk-js-otel"
extras = "packages/aws-durable-execution-sdk-js-extras"
worker = "packages/aws-durable-execution-sdk-js-microvm-worker"
worker = "packages/aws-durable-execution-sdk-js-compute-worker"
examples_package = "packages/aws-durable-execution-sdk-js-examples"
packages = [core, testing, otel, examples_package]
if has_microvm_packages:
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/type-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ mypy --install-types --non-interactive \
packages/aws-durable-execution-sdk-python-telemetry-exporter/tests

mypy --install-types --non-interactive \
packages/aws-durable-execution-sdk-python-microvm-worker/src/aws_durable_execution_sdk_python_microvm_worker \
packages/aws-durable-execution-sdk-python-microvm-worker/tests
packages/aws-durable-execution-sdk-python-compute-worker/src/aws_durable_execution_sdk_python_compute_worker \
packages/aws-durable-execution-sdk-python-compute-worker/tests

mypy --install-types --non-interactive \
packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras \
Expand Down
5 changes: 3 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ Do NOT add or modify **conformance tests** without coordinating with the team. C
(`aws-durable-execution-sdk-python`), the testing library
(`aws-durable-execution-sdk-python-testing`), the OpenTelemetry plugin
(`aws-durable-execution-sdk-python-otel`), the Durable Execution Telemetry
Exporter (`aws-durable-execution-sdk-python-telemetry-exporter`), the Lambda
MicroVM worker (`aws-durable-execution-sdk-python-microvm-worker`), the
Exporter (`aws-durable-execution-sdk-python-telemetry-exporter`), the compute
worker with the Lambda MicroVM worker in its `microvm` subpackage
(`aws-durable-execution-sdk-python-compute-worker`), the
extras package with custom operations such as `microvm`
(`aws-durable-execution-sdk-python-extras`), and examples
(`aws-durable-execution-sdk-python-examples`).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# AWS Durable Execution SDK for Python: MicroVM worker
# AWS Durable Execution SDK for Python: compute worker

> This package is experimental. Its API can change in any release.

The compute worker runs jobs from durable functions on compute that is defined outside the durable function. Each compute type has its own subpackage. Today the package has one subpackage: `aws_durable_execution_sdk_python_compute_worker.microvm`, the worker for AWS Lambda MicroVMs. The rest of this README describes the MicroVM worker.

Run jobs from a durable function inside an AWS Lambda MicroVM, and report each job's result to the durable function.

The worker runs in the MicroVM image, not in the durable function. It does not depend on the durable execution SDK. The job document is the same in every SDK language. So a durable function in any language can send jobs to this worker.

## Install

```console
pip install aws-durable-execution-sdk-python-microvm-worker
pip install aws-durable-execution-sdk-python-compute-worker
```

## Quick start

```python
import logging

from aws_durable_execution_sdk_python_microvm_worker import (
from aws_durable_execution_sdk_python_compute_worker.microvm import (
MicrovmJobContext,
start_microvm_worker,
)
Expand All @@ -42,7 +44,7 @@ The handler's return value becomes the durable function's result. An exception f
### Serve named routes

```python
from aws_durable_execution_sdk_python_microvm_worker import (
from aws_durable_execution_sdk_python_compute_worker.microvm import (
MicrovmJobContext,
start_microvm_worker,
)
Expand Down Expand Up @@ -73,7 +75,7 @@ The durable function sends a job to a route with `MicrovmRequestConfig(path=...)
```python
import subprocess

from aws_durable_execution_sdk_python_microvm_worker import MicrovmJobContext
from aws_durable_execution_sdk_python_compute_worker.microvm import MicrovmJobContext


def run_build(job_input: dict, context: MicrovmJobContext) -> dict:
Expand All @@ -91,7 +93,7 @@ A handler must be a plain function. An `async def` handler raises `TypeError`. C
```python
import asyncio

from aws_durable_execution_sdk_python_microvm_worker import MicrovmJobContext
from aws_durable_execution_sdk_python_compute_worker.microvm import MicrovmJobContext


async def build(job_input: dict) -> dict:
Expand Down Expand Up @@ -149,7 +151,7 @@ With `suspend_after`, the durable function suspends the MicroVM itself. The work

### Logging

The worker logs to the standard library logger `aws_durable_execution_sdk_python_microvm_worker`. Pass `logger=` to replace it. Configure `logging` in the image to see its INFO lines.
The worker logs to the standard library logger `aws_durable_execution_sdk_python_compute_worker.microvm`. Pass `logger=` to replace it. Configure `logging` in the image to see its INFO lines.

### Permissions

Expand All @@ -161,9 +163,9 @@ The worker needs boto3 1.43.35 or later.

## Reference

- [docs/worker.md](https://github.com/aws/aws-durable-execution-sdk-python/blob/main/packages/aws-durable-execution-sdk-python-microvm-worker/docs/worker.md): the request flow, the lifecycle hooks, idle suspend outcomes, the job documents, reporting, heartbeats, logging fields, and best practices.
- [docs/worker.md](https://github.com/aws/aws-durable-execution-sdk-python/blob/main/packages/aws-durable-execution-sdk-python-compute-worker/docs/worker.md): the request flow, the lifecycle hooks, idle suspend outcomes, the job documents, reporting, heartbeats, logging fields, and best practices.
- [extras](https://github.com/aws/aws-durable-execution-sdk-python/tree/main/packages/aws-durable-execution-sdk-python-extras): the `microvm` and `microvm_session` operations that send jobs.
- [Source](https://github.com/aws/aws-durable-execution-sdk-python/tree/main/packages/aws-durable-execution-sdk-python-microvm-worker/src/aws_durable_execution_sdk_python_microvm_worker): lower-level building blocks such as `MicrovmWorkerListener` and `CallbackReporter`.
- [Source](https://github.com/aws/aws-durable-execution-sdk-python/tree/main/packages/aws-durable-execution-sdk-python-compute-worker/src/aws_durable_execution_sdk_python_compute_worker/microvm): lower-level building blocks such as `MicrovmWorkerListener` and `CallbackReporter`.

## License

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ An explicit `heartbeat_interval_seconds` must be above 0 and at most 900, and it

## Logging

The worker logs to the standard library logger `aws_durable_execution_sdk_python_microvm_worker`, and passes its structured fields in `extra`. Every line about a job carries its `callbackId`. `CallbackReporter.create` and the heartbeats take the same `logger` argument. Configure `logging` in the image to see its INFO lines, for example with `logging.basicConfig(level=logging.INFO)`. Any object with the `logging.Logger` signatures for `info`, `warning`, and `error` can replace it. A logger that raises does not stop the worker: the line is dropped.
The worker logs to the standard library logger `aws_durable_execution_sdk_python_compute_worker.microvm`, and passes its structured fields in `extra`. Every line about a job carries its `callbackId`. `CallbackReporter.create` and the heartbeats take the same `logger` argument. Configure `logging` in the image to see its INFO lines, for example with `logging.basicConfig(level=logging.INFO)`. Any object with the `logging.Logger` signatures for `info`, `warning`, and `error` can replace it. A logger that raises does not stop the worker: the line is dropped.

## Permissions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["hatchling!=1.32.1,<1.33"]
build-backend = "hatchling.build"

[project]
name = "aws-durable-execution-sdk-python-microvm-worker"
name = "aws-durable-execution-sdk-python-compute-worker"
dynamic = ["version"]
description = 'Runs jobs from AWS Lambda durable functions inside an AWS Lambda MicroVM'
readme = "README.md"
Expand Down Expand Up @@ -39,23 +39,23 @@ Source = "https://github.com/aws/aws-durable-execution-sdk-python"
"../../NOTICE" = "NOTICE"

[tool.hatch.build.targets.wheel]
packages = ["src/aws_durable_execution_sdk_python_microvm_worker"]
packages = ["src/aws_durable_execution_sdk_python_compute_worker"]

[tool.hatch.build.targets.wheel.force-include]
"../../LICENSE" = "aws_durable_execution_sdk_python_microvm_worker/LICENSE"
"../../NOTICE" = "aws_durable_execution_sdk_python_microvm_worker/NOTICE"
"../../LICENSE" = "aws_durable_execution_sdk_python_compute_worker/LICENSE"
"../../NOTICE" = "aws_durable_execution_sdk_python_compute_worker/NOTICE"

[tool.hatch.version]
path = "src/aws_durable_execution_sdk_python_microvm_worker/__about__.py"
path = "src/aws_durable_execution_sdk_python_compute_worker/__about__.py"

[tool.hatch.publish.index]
disable = true

[tool.coverage.run]
source_pkgs = ["aws_durable_execution_sdk_python_microvm_worker"]
source_pkgs = ["aws_durable_execution_sdk_python_compute_worker"]
branch = true
parallel = true
omit = ["src/aws_durable_execution_sdk_python_microvm_worker/__about__.py"]
omit = ["src/aws_durable_execution_sdk_python_compute_worker/__about__.py"]

[tool.coverage.report]
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]
Expand All @@ -69,7 +69,7 @@ preview = true
select = ["E4", "E7", "E9", "F", "TID252"]

[tool.ruff.lint.isort]
known-first-party = ["aws_durable_execution_sdk_python_microvm_worker"]
known-first-party = ["aws_durable_execution_sdk_python_compute_worker"]
force-single-line = false
lines-after-imports = 2

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2026-present Amazon.com, Inc. or its affiliates.
#
# SPDX-License-Identifier: Apache-2.0
"""Runs jobs from AWS Lambda durable functions on compute that is defined
outside the durable function.

This package is experimental. Its API can change in any release.

Each compute type has its own subpackage. The worker for AWS Lambda MicroVMs
is in :mod:`aws_durable_execution_sdk_python_compute_worker.microvm`.
"""

from aws_durable_execution_sdk_python_compute_worker.__about__ import __version__


__all__ = ["__version__"]
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
has no ``AbortSignal``.
"""

from aws_durable_execution_sdk_python_microvm_worker.__about__ import __version__
from aws_durable_execution_sdk_python_microvm_worker.callback_reporter import (
from aws_durable_execution_sdk_python_compute_worker.__about__ import __version__
from aws_durable_execution_sdk_python_compute_worker.microvm.callback_reporter import (
MAX_CALLBACK_RESULT_BYTES,
CallbackReporter,
CallCancelledError,
Expand All @@ -21,18 +21,18 @@
ResultTooLargeError,
is_terminal_callback_error,
)
from aws_durable_execution_sdk_python_microvm_worker.logger import (
from aws_durable_execution_sdk_python_compute_worker.microvm.logger import (
MicrovmWorkerLogger,
)
from aws_durable_execution_sdk_python_microvm_worker.payload import (
from aws_durable_execution_sdk_python_compute_worker.microvm.payload import (
SUPPORTED_PAYLOAD_VERSION,
InvalidRunHookPayloadError,
MicrovmJobDocument,
MicrovmJobRequest,
MicrovmRunHookPayload,
RunHookRequest,
)
from aws_durable_execution_sdk_python_microvm_worker.worker import (
from aws_durable_execution_sdk_python_compute_worker.microvm.worker import (
HOOK_PATH_PREFIX,
MICROVM_JOB_PATH,
MicrovmJobContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from botocore.exceptions import ClientError, NoCredentialsError


from aws_durable_execution_sdk_python_microvm_worker.logger import (
from aws_durable_execution_sdk_python_compute_worker.microvm.logger import (
MicrovmWorkerLogger,
safe_get,
safe_logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@
import threading
from collections.abc import Callable

from aws_durable_execution_sdk_python_microvm_worker.callback_reporter import (
from aws_durable_execution_sdk_python_compute_worker.microvm.callback_reporter import (
CLOSED_CALLBACK_CODE,
CallbackReporter,
CancelScope,
error_code,
is_permanent_error,
is_terminal_callback_error,
)
from aws_durable_execution_sdk_python_microvm_worker.logger import (
from aws_durable_execution_sdk_python_compute_worker.microvm.logger import (
MicrovmWorkerLogger,
describe,
safe_logger,
)
from aws_durable_execution_sdk_python_microvm_worker.payload import is_finite_number
from aws_durable_execution_sdk_python_compute_worker.microvm.payload import (
is_finite_number,
)


MAX_HEARTBEAT_INTERVAL_SECONDS = 15 * 60.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

T = TypeVar("T")

DEFAULT_LOGGER_NAME = "aws_durable_execution_sdk_python_microvm_worker"
DEFAULT_LOGGER_NAME = "aws_durable_execution_sdk_python_compute_worker.microvm"
"""The name of the standard library logger that the worker uses by default."""


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

Both carry the same job fields. The contract is the same for every SDK
language, so a durable function in one language can drive a worker in
another. The JavaScript worker in ``@aws/durable-execution-sdk-js-microvm-worker``
another. The JavaScript worker in ``@aws/durable-execution-sdk-js-compute-worker``
defines the same documents. A change to the contract must be made in every
language.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
from botocore.config import Config
from botocore.exceptions import ClientError, NoCredentialsError

from aws_durable_execution_sdk_python_microvm_worker.callback_reporter import (
from aws_durable_execution_sdk_python_compute_worker.microvm.callback_reporter import (
TRANSIENT_4XX_CODES,
error_code,
)
from aws_durable_execution_sdk_python_microvm_worker.logger import safe_get
from aws_durable_execution_sdk_python_compute_worker.microvm.logger import safe_get


if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from typing import TYPE_CHECKING, Any

from aws_durable_execution_sdk_python_microvm_worker.callback_reporter import (
from aws_durable_execution_sdk_python_compute_worker.microvm.callback_reporter import (
CallbackReporter,
ResultSerializationError,
ResultTooLargeError,
is_terminal_callback_error,
)
from aws_durable_execution_sdk_python_microvm_worker.heartbeats import (
from aws_durable_execution_sdk_python_compute_worker.microvm.heartbeats import (
Heartbeats,
validate_heartbeat_interval,
)
from aws_durable_execution_sdk_python_microvm_worker.logger import (
from aws_durable_execution_sdk_python_compute_worker.microvm.logger import (
MicrovmWorkerLogger,
describe,
safe_logger,
)
from aws_durable_execution_sdk_python_microvm_worker.payload import (
from aws_durable_execution_sdk_python_compute_worker.microvm.payload import (
InvalidRunHookPayloadError,
MicrovmJobDocument,
MicrovmJobRequest,
RunHookRequest,
loads_strict,
)
from aws_durable_execution_sdk_python_microvm_worker.self_suspend import (
from aws_durable_execution_sdk_python_compute_worker.microvm.self_suspend import (
SUSPEND_CALL_TIMEOUT_SECONDS,
SUSPEND_GRACE_SECONDS,
SuspendOutcome,
Expand Down Expand Up @@ -2064,7 +2064,7 @@ def version_string(self) -> str:
# The base class names the exact Python version in the Server header.
# Every caller of the MicroVM endpoint would learn it, and no caller
# needs it.
return "aws-durable-execution-sdk-python-microvm-worker"
return "aws-durable-execution-sdk-python-compute-worker"


class _Exchange:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from botocore.exceptions import BotoCoreError, NoCredentialsError
from botocore.stub import Stubber

from aws_durable_execution_sdk_python_microvm_worker import callback_reporter
from aws_durable_execution_sdk_python_microvm_worker.callback_reporter import (
from aws_durable_execution_sdk_python_compute_worker.microvm import callback_reporter
from aws_durable_execution_sdk_python_compute_worker.microvm.callback_reporter import (
CLOSED_CALLBACK_CODE,
MAX_CALLBACK_RESULT_BYTES,
CallbackReporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

import pytest

from aws_durable_execution_sdk_python_microvm_worker.callback_reporter import (
from aws_durable_execution_sdk_python_compute_worker.microvm.callback_reporter import (
CallbackReporter,
)
from aws_durable_execution_sdk_python_microvm_worker.heartbeats import (
from aws_durable_execution_sdk_python_compute_worker.microvm.heartbeats import (
MAX_HEARTBEAT_INTERVAL_SECONDS,
MAX_QUICK_HEARTBEAT_RETRIES,
Heartbeats,
Expand Down
Loading
Loading