Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(data-warehouse): add map run, version, alias and activity tables to aws step functions (#118510)

Tom Owers701429938a89
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index cb4c86482fe1..0bff6e2b72fb 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -1321,10 +1321,10 @@ Today (3): `execution_history`, `executions`, `state_machines`
Diffed against: <https://raw.githubusercontent.com/boto/botocore/develop/botocore/data/stepfunctions/2016-11-23/service-2.json>
-- [ ] `State machine versions (ListStateMachineVersions, POST /)` — resolve stateMachineVersionArn on executions and compare outcomes across deployed versions (high)
-- [ ] `State machine aliases (ListStateMachineAliases and DescribeStateMachineAlias, POST /)` — resolve stateMachineAliasArn on executions and compare results across deployment aliases (high)
-- [ ] `Activities (ListActivities, POST /)` — resolve activity resource ARNs in execution history to worker activity names (high)
-- [ ] `Map Runs and child executions (ListMapRuns, DescribeMapRun and ListExecutions with mapRunArn, POST /)` — measure distributed processing progress, failed items, child execution outcomes, and redrive results (high)
+- [x] `State machine versions (ListStateMachineVersions, POST /)` — resolve stateMachineVersionArn on executions and compare outcomes across deployed versions (high)
+- [x] `State machine aliases (ListStateMachineAliases and DescribeStateMachineAlias, POST /)` — resolve stateMachineAliasArn on executions and compare results across deployment aliases (high)
+- [x] `Activities (ListActivities, POST /)` — resolve activity resource ARNs in execution history to worker activity names (high)
+- [x] `Map Runs and child executions (ListMapRuns, DescribeMapRun and ListExecutions with mapRunArn, POST /)` — measure distributed processing progress, failed items, child execution outcomes, and redrive results (high)
Note: The official SDK model was compared with ListStateMachines, ListExecutions, and GetExecutionHistory in the source. Version and alias ARNs already appear in execution rows; activity resource ARNs appear in history events. Map Runs require requests for each parent execution, then describe and child execution calls. Standalone Express execution history is unavailable through these operations; task polling, writes, and existing object enrichment are excluded.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/aws_step_functions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/aws_step_functions.py
index e4b8617d6660..11967b79decf 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/aws_step_functions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/aws_step_functions.py
@@ -16,7 +16,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.aws_step_f
CONTENT_TYPE,
ENDPOINTS,
ERROR_MESSAGES,
+ MACHINE_CHILD_ENDPOINTS,
+ MAP_RUN_ENDPOINTS,
PAGE_SIZE,
+ PROBE_PARENT_LIMIT,
TARGET_PREFIXES,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session
@@ -47,6 +50,15 @@ class AwsStepFunctionsResumeConfig:
execution_arns: list[str] = field(default_factory=list)
executions_done: bool = False
history_token: str | None = None
+ child_token: str | None = None
+ children_done: bool = False
+ alias_arns: list[str] = field(default_factory=list)
+ map_run_token: str | None = None
+ map_run_arns: list[str] = field(default_factory=list)
+ map_runs_done: bool = False
+ map_run_execution_token: str | None = None
+ activity_token: str | None = None
+ activities_done: bool = False
class AwsStepFunctionsClient:
@@ -133,13 +145,22 @@ class AwsStepFunctionsClient:
payload["nextToken"] = token
return self.request(ENDPOINTS[endpoint].operation, payload)
+ def describe(self, operation: str, payload: dict[str, Any]) -> dict[str, Any] | None:
+ # A resource listed earlier in the walk can be deleted before its describe call.
+ try:
+ return self.request(operation, payload)
+ except AwsStepFunctionsError as error:
+ if error.code == "ResourceNotFound":
+ return None
+ raise
+
def close(self) -> None:
self.session.close()
def normalize_row(item: dict[str, Any]) -> dict[str, Any]:
row = {re.sub(r"(?<=[a-z0-9])(?=[A-Z])", "_", key).lower(): value for key, value in item.items()}
- for key in ("creation_date", "start_date", "stop_date", "redrive_date", "timestamp"):
+ for key in ("creation_date", "update_date", "start_date", "stop_date", "redrive_date", "timestamp"):
value = row.get(key)
if isinstance(value, int | float) and not isinstance(value, bool):
row[key] = datetime.fromtimestamp(value, tz=UTC)
@@ -155,7 +176,13 @@ def get_rows(
state = state or AwsStepFunctionsResumeConfig()
while True:
rows: list[dict[str, Any]] = []
- if not state.machine_arns:
+ if endpoint == "activities":
+ if state.activities_done:
+ break
+ page = client.page("activities", state.activity_token)
+ rows = [normalize_row(item) for item in page["activities"]]
+ state = replace(state, activity_token=page.get("nextToken"), activities_done=not page.get("nextToken"))
+ elif not state.machine_arns:
if state.machines_done:
break
page = client.page("state_machines", state.machine_token)
@@ -164,8 +191,56 @@ def get_rows(
if endpoint == "state_machines":
rows = [normalize_row(item) for item in machines]
else:
+ # Versions and aliases exist for Express machines too; only Standard executions can be listed.
state = replace(
- state, machine_arns=[item["stateMachineArn"] for item in machines if item["type"] == "STANDARD"]
+ state,
+ machine_arns=[
+ item["stateMachineArn"]
+ for item in machines
+ if endpoint in MACHINE_CHILD_ENDPOINTS or item["type"] == "STANDARD"
+ ],
+ )
+ elif endpoint in MACHINE_CHILD_ENDPOINTS:
+ machine_arn = state.machine_arns[0]
+ if state.alias_arns:
+ alias = client.describe("DescribeStateMachineAlias", {"stateMachineAliasArn": state.alias_arns[0]})
+ rows = [normalize_row({**alias, "stateMachineArn": machine_arn})] if alias else []
+ state = replace(state, alias_arns=state.alias_arns[1:])
+ elif state.children_done:
+ state = replace(state, machine_arns=state.machine_arns[1:], child_token=None, children_done=False)
+ else:
+ page = client.page(endpoint, state.child_token, stateMachineArn=machine_arn)
+ items = page[ENDPOINTS[endpoint].result_key]
+ state = replace(state, child_token=page.get("nextToken"), children_done=not page.get("nextToken"))
+ if endpoint == "state_machine_versions":
+ rows = [normalize_row({**item, "stateMachineArn": machine_arn}) for item in items]
+ else:
+ state = replace(state, alias_arns=[item["stateMachineAliasArn"] for item in items])
+ elif state.execution_arns and endpoint in MAP_RUN_ENDPOINTS:
+ if state.map_run_arns:
+ map_run_arn = state.map_run_arns[0]
+ if endpoint == "map_runs":
+ map_run = client.describe("DescribeMapRun", {"mapRunArn": map_run_arn})
+ rows = [normalize_row({**map_run, "stateMachineArn": state.machine_arns[0]})] if map_run else []
+ state = replace(state, map_run_arns=state.map_run_arns[1:])
+ else:
+ page = client.page("map_run_executions", state.map_run_execution_token, mapRunArn=map_run_arn)
+ rows = [normalize_row({**item, "mapRunArn": map_run_arn}) for item in page["executions"]]
+ token = page.get("nextToken")
+ state = replace(
+ state,
+ map_run_execution_token=token,
+ map_run_arns=state.map_run_arns if token else state.map_run_arns[1:],
+ )
+ elif state.map_runs_done:
+ state = replace(state, execution_arns=state.execution_arns[1:], map_run_token=None, map_runs_done=False)
+ else:
+ page = client.page("map_runs", state.map_run_token, executionArn=state.execution_arns[0])
+ state = replace(
+ state,
+ map_run_token=page.get("nextToken"),
+ map_runs_done=not page.get("nextToken"),
+ map_run_arns=[item["mapRunArn"] for item in page["mapRuns"]],
)
elif state.execution_arns:
execution_arn = state.execution_arns[0]
@@ -226,12 +301,48 @@ def aws_step_functions_source(
)
+def probe_machine_children(client: AwsStepFunctionsClient, schema_name: str, machine_arn: str) -> bool:
+ page = client.request(ENDPOINTS[schema_name].operation, {"stateMachineArn": machine_arn, "maxResults": 1})
+ if schema_name == "state_machine_versions":
+ return True
+ if not page["stateMachineAliases"]:
+ return False
+ client.describe(
+ "DescribeStateMachineAlias", {"stateMachineAliasArn": page["stateMachineAliases"][0]["stateMachineAliasArn"]}
+ )
+ return True
+
+
+def probe_map_runs(client: AwsStepFunctionsClient, schema_name: str, execution_arn: str) -> bool:
+ page = client.request("ListMapRuns", {"executionArn": execution_arn, "maxResults": 1})
+ if not page["mapRuns"]:
+ return False
+ map_run_arn = page["mapRuns"][0]["mapRunArn"]
+ if schema_name == "map_runs":
+ client.describe("DescribeMapRun", {"mapRunArn": map_run_arn})
+ else:
+ client.request("ListExecutions", {"mapRunArn": map_run_arn, "maxResults": 1})
+ return True
+
+
def probe(client: AwsStepFunctionsClient, schema_name: str | None) -> None:
+ if schema_name == "activities":
+ client.request("ListActivities", {"maxResults": 1})
+ return
page = client.request("ListStateMachines", {"maxResults": 1})
if schema_name is None or schema_name == "state_machines":
return
+ parents_checked = 0
while True:
for machine in page["stateMachines"]:
+ if schema_name in MACHINE_CHILD_ENDPOINTS:
+ parents_checked += 1
+ if (
+ probe_machine_children(client, schema_name, machine["stateMachineArn"])
+ or parents_checked >= PROBE_PARENT_LIMIT
+ ):
+ return
+ continue
if machine["type"] != "STANDARD":
continue
executions = client.request(
@@ -241,16 +352,22 @@ def probe(client: AwsStepFunctionsClient, schema_name: str | None) -> None:
return
while True:
if executions["executions"]:
- client.request(
- "GetExecutionHistory",
- {
- "executionArn": executions["executions"][0]["executionArn"],
- "maxResults": 1,
- "includeExecutionData": False,
- "reverseOrder": False,
- },
- )
- return
+ execution_arn = executions["executions"][0]["executionArn"]
+ if schema_name in MAP_RUN_ENDPOINTS:
+ parents_checked += 1
+ if probe_map_runs(client, schema_name, execution_arn) or parents_checked >= PROBE_PARENT_LIMIT:
+ return
+ else:
+ client.request(
+ "GetExecutionHistory",
+ {
+ "executionArn": execution_arn,
+ "maxResults": 1,
+ "includeExecutionData": False,
+ "reverseOrder": False,
+ },
+ )
+ return
if not executions.get("nextToken"):
break
executions = client.request(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/canonical_descriptions.py
index d77d718a22a5..d42ed00c2884 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/canonical_descriptions.py
@@ -25,6 +25,8 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"stop_date": "The execution completion time, in UTC, when available.",
"redrive_count": "The number of times AWS restarted the execution through redrive.",
"redrive_date": "The most recent redrive time, in UTC.",
+ "state_machine_version_arn": "The ARN of the state machine version that ran the execution, when available.",
+ "state_machine_alias_arn": "The ARN of the state machine alias that started the execution, when available.",
},
},
"execution_history": {
@@ -39,4 +41,67 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"timestamp": "The event time, in UTC.",
},
},
+ "state_machine_versions": {
+ "description": "Published versions of each state machine. Join on executions.state_machine_version_arn.",
+ "docs_url": "https://docs.aws.amazon.com/step-functions/latest/apireference/API_ListStateMachineVersions.html",
+ "columns": {
+ "state_machine_version_arn": "The ARN that identifies the state machine version.",
+ "state_machine_arn": "The ARN of the state machine that owns the version.",
+ "creation_date": "The time AWS created the version, in UTC.",
+ },
+ },
+ "state_machine_aliases": {
+ "description": "Aliases of each state machine. Join on executions.state_machine_alias_arn.",
+ "docs_url": "https://docs.aws.amazon.com/step-functions/latest/apireference/API_DescribeStateMachineAlias.html",
+ "columns": {
+ "state_machine_alias_arn": "The ARN that identifies the state machine alias.",
+ "state_machine_arn": "The ARN of the state machine that owns the alias.",
+ "name": "The alias name.",
+ "description": "The alias description.",
+ "routing_configuration": "The versions the alias routes executions to, with the percentage weight of each.",
+ "creation_date": "The time AWS created the alias, in UTC.",
+ "update_date": "The time AWS last updated the alias, in UTC.",
+ },
+ },
+ "activities": {
+ "description": "Activities in the configured AWS region. Activity ARNs appear in activity events of execution history.",
+ "docs_url": "https://docs.aws.amazon.com/step-functions/latest/apireference/API_ListActivities.html",
+ "columns": {
+ "activity_arn": "The ARN that identifies the activity.",
+ "name": "The activity name.",
+ "creation_date": "The time AWS created the activity, in UTC.",
+ },
+ },
+ "map_runs": {
+ "description": "Distributed Map runs started by Standard executions, with item and child execution counts.",
+ "docs_url": "https://docs.aws.amazon.com/step-functions/latest/apireference/API_DescribeMapRun.html",
+ "columns": {
+ "map_run_arn": "The ARN that identifies the Map Run.",
+ "execution_arn": "The ARN of the execution that started the Map Run.",
+ "state_machine_arn": "The ARN of the state machine that ran the parent execution.",
+ "status": "The Map Run status reported by AWS.",
+ "start_date": "The Map Run start time, in UTC.",
+ "stop_date": "The Map Run completion time, in UTC, when available.",
+ "max_concurrency": "The maximum number of child executions that can run in parallel.",
+ "tolerated_failure_percentage": "The maximum percentage of failed items before the Map Run fails.",
+ "tolerated_failure_count": "The maximum number of failed items before the Map Run fails.",
+ "item_counts": "Counts of processed items by status, such as succeeded, failed, and pending.",
+ "execution_counts": "Counts of child workflow executions by status.",
+ "redrive_count": "The number of times AWS redrove the Map Run.",
+ "redrive_date": "The most recent redrive time, in UTC.",
+ },
+ },
+ "map_run_executions": {
+ "description": "Child workflow executions started by Distributed Map runs, including Express children.",
+ "docs_url": "https://docs.aws.amazon.com/step-functions/latest/apireference/API_ListExecutions.html",
+ "columns": {
+ "execution_arn": "The ARN that identifies the child execution.",
+ "map_run_arn": "The ARN of the Map Run that started the child execution.",
+ "state_machine_arn": "The ARN of the child workflow state machine.",
+ "status": "The child execution status reported by AWS.",
+ "start_date": "The child execution start time, in UTC.",
+ "stop_date": "The child execution completion time, in UTC, when available.",
+ "item_count": "The number of items the child execution processed.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/settings.py
index d97048513764..7b7be3b59efd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/settings.py
@@ -4,6 +4,8 @@ API_VERSION = "2016-11-23"
TARGET_PREFIXES = {API_VERSION: "AWSStepFunctions"}
CONTENT_TYPE = "application/x-amz-json-1.0"
PAGE_SIZE = 100
+# Parents a permission probe checks for a child before it accepts the credentials.
+PROBE_PARENT_LIMIT = 20
@frozen
@@ -23,14 +25,40 @@ ENDPOINTS = {
"execution_history": StepFunctionsEndpoint(
operation="GetExecutionHistory", result_key="events", primary_keys=("execution_arn", "id")
),
+ "state_machine_versions": StepFunctionsEndpoint(
+ operation="ListStateMachineVersions",
+ result_key="stateMachineVersions",
+ primary_keys=("state_machine_version_arn",),
+ ),
+ "state_machine_aliases": StepFunctionsEndpoint(
+ operation="ListStateMachineAliases",
+ result_key="stateMachineAliases",
+ primary_keys=("state_machine_alias_arn",),
+ ),
+ "activities": StepFunctionsEndpoint(
+ operation="ListActivities", result_key="activities", primary_keys=("activity_arn",)
+ ),
+ "map_runs": StepFunctionsEndpoint(operation="ListMapRuns", result_key="mapRuns", primary_keys=("map_run_arn",)),
+ "map_run_executions": StepFunctionsEndpoint(
+ operation="ListExecutions", result_key="executions", primary_keys=("execution_arn",)
+ ),
}
+MACHINE_CHILD_ENDPOINTS = frozenset({"state_machine_versions", "state_machine_aliases"})
+MAP_RUN_ENDPOINTS = frozenset({"map_runs", "map_run_executions"})
ENDPOINT_DESCRIPTIONS = {
"state_machines": "State machines in the configured AWS region, including Standard and Express workflows.",
"executions": "Execution status and times for Standard workflows in the configured AWS region.",
"execution_history": "History events for Standard workflow executions, without input or output payloads.",
+ "state_machine_versions": "Published versions of each state machine in the configured AWS region.",
+ "state_machine_aliases": "Aliases of each state machine, with the versions they route executions to.",
+ "activities": "Activities that workers poll for tasks in the configured AWS region.",
+ "map_runs": "Distributed Map runs started by Standard workflow executions, with item and child execution counts.",
+ "map_run_executions": "Child workflow executions started by each Distributed Map run.",
}
PERMISSION_MESSAGE = (
- "Grant states:ListStateMachines, states:ListExecutions, and states:GetExecutionHistory for the tables you select."
+ "Grant states:ListStateMachines, states:ListExecutions, states:GetExecutionHistory, "
+ "states:ListStateMachineVersions, states:ListStateMachineAliases, states:DescribeStateMachineAlias, "
+ "states:ListActivities, states:ListMapRuns, and states:DescribeMapRun for the tables you select."
)
ERROR_MESSAGES = {
"AccessDenied": PERMISSION_MESSAGE,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/source.py
index 4243b132fdfc..3abae1196c00 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/source.py
@@ -112,9 +112,11 @@ class AwsStepFunctionsSource(ResumableSource[AwsStepFunctionsSourceConfig, AwsSt
category=DataWarehouseSourceCategory.ENGINEERING___MONITORING,
label="AWS Step Functions",
caption=(
- "Sync state machines, executions, and execution history from one AWS region. "
- "Grant `states:ListStateMachines`, `states:ListExecutions`, and `states:GetExecutionHistory` for the tables you select. "
- "Executions and history cover Standard workflows only. History excludes input and output payloads. "
+ "Sync state machines, versions, aliases, activities, executions, execution history, and Distributed Map runs from one AWS region. "
+ "Grant `states:ListStateMachines`, `states:ListExecutions`, `states:GetExecutionHistory`, "
+ "`states:ListStateMachineVersions`, `states:ListStateMachineAliases`, `states:DescribeStateMachineAlias`, "
+ "`states:ListActivities`, `states:ListMapRuns`, and `states:DescribeMapRun` for the tables you select. "
+ "Executions, history, and Map runs cover Standard workflows only. History excludes input and output payloads. "
"All tables use full refresh because these APIs have no time filter."
),
iconPath="/static/services/aws_step_functions.png",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/tests/test_aws_step_functions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/tests/test_aws_step_functions.py
index 3ac7047d5e11..56cd163c721e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/tests/test_aws_step_functions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_step_functions/tests/test_aws_step_functions.py
@@ -35,6 +35,10 @@ SM1 = "arn:aws:states:us-east-1:123456789012:stateMachine:example-one"
SM2 = "arn:aws:states:us-east-1:123456789012:stateMachine:example-two"
EXPRESS = "arn:aws:states:us-east-1:123456789012:stateMachine:example-express"
EXECUTIONS = [f"arn:aws:states:us-east-1:123456789012:execution:example-one:run-{i}" for i in range(4)]
+ALIASES = [f"{SM1}:alias-{i}" for i in range(2)] + [f"{SM2}:alias-0"]
+MAP_RUNS = [f"arn:aws:states:us-east-1:123456789012:mapRun:example-one/map:run-{i}" for i in range(2)]
+DELETED_ALIAS = f"{SM2}:alias-deleted"
+DELETED_MAP_RUN = "arn:aws:states:us-east-1:123456789012:mapRun:example-two/map:run-deleted"
@pytest.fixture
@@ -100,7 +104,7 @@ def install_pages(session: MagicMock) -> None:
def post(url: str, **kwargs: Any) -> requests.Response:
payload = json.loads(kwargs["data"])
operation = kwargs["headers"]["X-Amz-Target"].split(".")[-1]
- assert payload["maxResults"] <= 1000
+ assert payload.get("maxResults", 0) <= 1000
assert not {"startDate", "startTime", "updatedAt", "statusFilter"}.intersection(payload)
token = payload.get("nextToken")
if operation == "ListStateMachines":
@@ -116,6 +120,80 @@ def install_pages(session: MagicMock) -> None:
"m3": {"stateMachines": [{"stateMachineArn": SM2, "type": "STANDARD"}]},
}
return response(200, machine_pages[token])
+ if operation == "ListActivities":
+ activity_pages: dict[str | None, dict[str, Any]] = {
+ None: {
+ "activities": [{"activityArn": "a0", "creationDate": 1}, {"activityArn": "a1"}],
+ "nextToken": "a2",
+ },
+ "a2": {"activities": [{"activityArn": "a2"}]},
+ }
+ return response(200, activity_pages[token])
+ if operation == "ListStateMachineVersions":
+ version_pages: dict[tuple[str, str | None], dict[str, Any]] = {
+ (EXPRESS, None): {"stateMachineVersions": [{"stateMachineVersionArn": f"{EXPRESS}:1"}]},
+ (SM1, None): {"stateMachineVersions": [{"stateMachineVersionArn": f"{SM1}:1"}], "nextToken": "v2"},
+ (SM1, "v2"): {"stateMachineVersions": [{"stateMachineVersionArn": f"{SM1}:2"}]},
+ (SM2, None): {"stateMachineVersions": []},
+ }
+ return response(200, version_pages[(payload["stateMachineArn"], token)])
+ if operation == "ListStateMachineAliases":
+ alias_pages: dict[tuple[str, str | None], dict[str, Any]] = {
+ (EXPRESS, None): {"stateMachineAliases": []},
+ (SM1, None): {"stateMachineAliases": [{"stateMachineAliasArn": ALIASES[0]}], "nextToken": "l2"},
+ (SM1, "l2"): {"stateMachineAliases": [{"stateMachineAliasArn": ALIASES[1]}]},
+ (SM2, None): {
+ "stateMachineAliases": [
+ {"stateMachineAliasArn": DELETED_ALIAS},
+ {"stateMachineAliasArn": ALIASES[2]},
+ ]
+ },
+ }
+ return response(200, alias_pages[(payload["stateMachineArn"], token)])
+ if operation == "DescribeStateMachineAlias":
+ alias_arn = payload["stateMachineAliasArn"]
+ if alias_arn == DELETED_ALIAS:
+ return response(400, {"__type": "ResourceNotFound", "message": "Example missing alias"})
+ return response(
+ 200,
+ {
+ "stateMachineAliasArn": alias_arn,
+ "routingConfiguration": [{"stateMachineVersionArn": f"{SM1}:1", "weight": 100}],
+ "updateDate": 5,
+ },
+ )
+ if operation == "ListMapRuns":
+ map_run_pages: dict[tuple[str, str | None], dict[str, Any]] = {
+ (EXECUTIONS[0], None): {"mapRuns": [{"mapRunArn": MAP_RUNS[0]}], "nextToken": "r2"},
+ (EXECUTIONS[0], "r2"): {"mapRuns": []},
+ (EXECUTIONS[2], None): {"mapRuns": [{"mapRunArn": MAP_RUNS[1]}]},
+ (EXECUTIONS[3], None): {"mapRuns": [{"mapRunArn": DELETED_MAP_RUN}]},
+ }
+ return response(200, map_run_pages.get((payload["executionArn"], token), {"mapRuns": []}))
+ if operation == "DescribeMapRun":
+ if payload["mapRunArn"] == DELETED_MAP_RUN:
+ return response(400, {"__type": "ResourceNotFound", "message": "Example missing map run"})
+ return response(
+ 200,
+ {
+ "mapRunArn": payload["mapRunArn"],
+ "executionArn": EXECUTIONS[0],
+ "startDate": 10,
+ "itemCounts": {"failed": 1, "total": 3},
+ },
+ )
+ if operation == "ListExecutions" and "mapRunArn" in payload:
+ assert "stateMachineArn" not in payload
+ child_pages: dict[tuple[str, str | None], dict[str, Any]] = {
+ (MAP_RUNS[0], None): {
+ "executions": [{"executionArn": f"{MAP_RUNS[0]}:child-{i}"} for i in range(2)],
+ "nextToken": "c2",
+ },
+ (MAP_RUNS[0], "c2"): {"executions": [{"executionArn": f"{MAP_RUNS[0]}:child-2"}]},
+ (MAP_RUNS[1], None): {"executions": []},
+ (DELETED_MAP_RUN, None): {"executions": []},
+ }
+ return response(200, child_pages[(payload["mapRunArn"], token)])
if operation == "ListExecutions":
machine = payload["stateMachineArn"]
assert machine != EXPRESS
@@ -144,7 +222,19 @@ def install_pages(session: MagicMock) -> None:
session.post.side_effect = post
[email protected]("endpoint,count", [("state_machines", 3), ("executions", 4), ("execution_history", 8)])
+ "endpoint,count",
+ [
+ ("state_machines", 3),
+ ("executions", 4),
+ ("execution_history", 8),
+ ("activities", 3),
+ ("state_machine_versions", 3),
+ ("state_machine_aliases", 3),
+ ("map_runs", 2),
+ ("map_run_executions", 3),
+ ],
+)
def test_full_refresh_pagination_and_resume_at_every_batch(
config: AwsStepFunctionsSourceConfig, session: MagicMock, endpoint: str, count: int
) -> None:
@@ -166,6 +256,18 @@ def test_full_refresh_pagination_and_resume_at_every_batch(
if endpoint == "execution_history":
assert {row["execution_arn"] for row in expected} == set(EXECUTIONS)
assert {row["state_machine_arn"] for row in expected} == {SM1, SM2}
+ if endpoint == "state_machine_versions":
+ assert {row["state_machine_arn"] for row in expected} == {EXPRESS, SM1}
+ if endpoint == "state_machine_aliases":
+ assert [row["state_machine_alias_arn"] for row in expected] == ALIASES
+ assert [row["state_machine_arn"] for row in expected] == [SM1, SM1, SM2]
+ assert {row["update_date"] for row in expected} == {datetime.fromtimestamp(5, UTC)}
+ if endpoint == "map_runs":
+ assert [row["map_run_arn"] for row in expected] == MAP_RUNS
+ assert {row["state_machine_arn"] for row in expected} == {SM1}
+ assert expected[0]["item_counts"] == {"failed": 1, "total": 3}
+ if endpoint == "map_run_executions":
+ assert {row["map_run_arn"] for row in expected} == {MAP_RUNS[0]}
batch_count = len(list(source_items(aws_step_functions_source(config, endpoint, API_VERSION, manager()))))
for stop_after in range(1, batch_count + 1):
interrupted_manager = manager()
@@ -178,7 +280,9 @@ def test_full_refresh_pagination_and_resume_at_every_batch(
session.close.assert_called()
[email protected]("schema_name", [None, "state_machines", "executions", "execution_history"])
+ "schema_name", [None, "state_machines", "executions", "execution_history", "activities", "state_machine_aliases"]
+)
@pytest.mark.parametrize(
"code,valid_at_create",
[
@@ -283,44 +387,92 @@ def test_invalid_config_does_not_send_credentials(
assert network.requests_log == []
[email protected]("schema_name", [None, "state_machines", "executions", "execution_history"])
-def test_permission_probe_walks_to_standard_execution(
- config: AwsStepFunctionsSourceConfig, schema_name: str | None
+ "schema_name,answers,last_call",
+ [
+ (None, [], ("ListStateMachines", {"maxResults": 1})),
+ ("state_machines", [], ("ListStateMachines", {"maxResults": 1})),
+ (
+ "executions",
+ [{"executions": [{"executionArn": EXECUTIONS[0]}]}],
+ ("ListExecutions", {"stateMachineArn": SM1, "maxResults": 1}),
+ ),
+ (
+ "execution_history",
+ [{"executions": [{"executionArn": EXECUTIONS[0]}]}, {"events": [{"id": 1}]}],
+ (
+ "GetExecutionHistory",
+ {"executionArn": EXECUTIONS[0], "maxResults": 1, "includeExecutionData": False, "reverseOrder": False},
+ ),
+ ),
+ (
+ "state_machine_versions",
+ [{"stateMachineVersions": []}],
+ ("ListStateMachineVersions", {"stateMachineArn": EXPRESS, "maxResults": 1}),
+ ),
+ (
+ "state_machine_aliases",
+ [
+ {"stateMachineAliases": []},
+ {"stateMachineAliases": [{"stateMachineAliasArn": ALIASES[0]}]},
+ {"stateMachineAliasArn": ALIASES[0]},
+ ],
+ ("DescribeStateMachineAlias", {"stateMachineAliasArn": ALIASES[0]}),
+ ),
+ (
+ "map_runs",
+ [
+ {"executions": [{"executionArn": EXECUTIONS[0]}], "nextToken": "e2"},
+ {"mapRuns": []},
+ {"executions": [{"executionArn": EXECUTIONS[1]}]},
+ {"mapRuns": [{"mapRunArn": MAP_RUNS[0]}]},
+ {"mapRunArn": MAP_RUNS[0]},
+ ],
+ ("DescribeMapRun", {"mapRunArn": MAP_RUNS[0]}),
+ ),
+ (
+ "map_run_executions",
+ [
+ {"executions": [{"executionArn": EXECUTIONS[0]}]},
+ {"mapRuns": [{"mapRunArn": MAP_RUNS[0]}]},
+ {"executions": []},
+ ],
+ ("ListExecutions", {"mapRunArn": MAP_RUNS[0], "maxResults": 1}),
+ ),
+ (
+ "map_run_executions",
+ [{"executions": [{"executionArn": EXECUTIONS[0]}]}, {"mapRuns": []}, {"stateMachines": []}],
+ ("ListStateMachines", {"maxResults": 1, "nextToken": "m2"}),
+ ),
+ ],
+)
+def test_permission_probe_walks_to_the_table_operation(
+ config: AwsStepFunctionsSourceConfig,
+ schema_name: str | None,
+ answers: list[dict[str, Any]],
+ last_call: tuple[str, dict[str, Any]],
) -> None:
- answers = [
- ScriptedResponse(
- json={
- "stateMachines": [
- {"stateMachineArn": EXPRESS, "type": "EXPRESS"},
- {"stateMachineArn": SM1, "type": "STANDARD"},
- ],
- "nextToken": "m2",
- }
- )
- ]
- if schema_name in ("executions", "execution_history"):
- answers.append(ScriptedResponse(json={"executions": [{"executionArn": EXECUTIONS[0]}]}))
- if schema_name == "execution_history":
- answers.append(ScriptedResponse(json={"events": [{"id": 1}]}))
- with scripted_network(answers) as network:
+ machines = {
+ "stateMachines": [
+ {"stateMachineArn": EXPRESS, "type": "EXPRESS"},
+ {"stateMachineArn": SM1, "type": "STANDARD"},
+ ],
+ "nextToken": "m2",
+ }
+ with scripted_network([ScriptedResponse(json=body) for body in [machines, *answers]]) as network:
assert validate_credentials(config, schema_name, API_VERSION) == (True, None)
calls = network.requests_log
- if schema_name in (None, "state_machines"):
- assert len(calls) == 1
- elif schema_name == "executions":
- assert calls[-1].headers["x-amz-target"].endswith(".ListExecutions")
- assert calls[-1].json() == {"stateMachineArn": SM1, "maxResults": 1}
- else:
- assert calls[-1].headers["x-amz-target"].endswith(".GetExecutionHistory")
- assert calls[-1].json() == {
- "executionArn": EXECUTIONS[0],
- "maxResults": 1,
- "includeExecutionData": False,
- "reverseOrder": False,
- }
+ assert len(calls) == len(answers) + 1
+ assert (calls[-1].headers["x-amz-target"].split(".")[-1], calls[-1].json()) == last_call
+
+
+def test_activities_probe_skips_state_machines(config: AwsStepFunctionsSourceConfig) -> None:
+ with scripted_network([ScriptedResponse(json={"activities": []})]) as network:
+ assert validate_credentials(config, "activities", API_VERSION) == (True, None)
+ assert [request.headers["x-amz-target"] for request in network.requests_log] == ["AWSStepFunctions.ListActivities"]
[email protected]("schema_name", ["executions", "execution_history"])
[email protected]("schema_name", ["executions", "execution_history", "map_runs"])
def test_probe_handles_empty_and_express_only_accounts(config: AwsStepFunctionsSourceConfig, schema_name: str) -> None:
with scripted_network(
[