Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(sfn): match DynamoDB errors and Lambda reads (#2107)

Jay Janssen94090c473ffd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 86a34262..38ee978d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,8 @@ Versioning follows [Semantic Versioning](https://semver.org/).
## [Unreleased]
### Fixed
+- **Step Functions — optimized DynamoDB error names** — conditional failures and other service errors now use the `DynamoDB.` prefix so exact `Catch` and `Retry` handlers match AWS.
+- **Step Functions — Lambda `GetFunction` SDK integration** — workflows can read function configuration, code metadata and tags through `aws-sdk:lambda:getFunction`, including qualified reads.
- **Secrets Manager — force delete of a secret scheduled for deletion** — `DeleteSecret` with `ForceDeleteWithoutRecovery` returned `InvalidRequestException` for a secret already scheduled for deletion. It now deletes the secret permanently. Reported by @fabio-andre-rodrigues.
## [1.5.24] — 2026-10-08
diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.py
index 2dcd79b4..77ee80ff 100644
--- a/ministack/services/stepfunctions.py
+++ b/ministack/services/stepfunctions.py
@@ -3406,7 +3406,10 @@ def _invoke_dynamodb(op_name, input_data):
status, _, body = fn(input_data)
result = json.loads(body) if body else {}
if status >= 400:
- error_type = result.get("__type", "DynamoDB.AmazonDynamoDBException")
+ # Optimized integrations use DynamoDB.*, unlike the SDK's DynamoDb.*.
+ # The service wire error may be bare, already prefixed, or #-qualified.
+ error_name = result.get("__type", "AmazonDynamoDBException").rsplit("#", 1)[-1].rsplit(".", 1)[-1]
+ error_type = f"DynamoDB.{error_name}"
raise _ExecutionError(error_type, result.get("message", ""))
return result
@@ -4363,9 +4366,11 @@ def _dispatch_aws_sdk_lambda_rest(service_info, service_name, action, input_data
"/2015-03-31/functions/"
f"{quote(str(function_name), safe=':')}/aliases/{quote(str(alias_name), safe='')}"
)
- elif pascal_action == "GetFunctionConfiguration":
+ elif pascal_action in {"GetFunction", "GetFunctionConfiguration"}:
function_name = input_data.get("FunctionName", "")
- path = f"/2015-03-31/functions/{quote(str(function_name), safe=':')}/configuration"
+ path = f"/2015-03-31/functions/{quote(str(function_name), safe=':')}"
+ if pascal_action == "GetFunctionConfiguration":
+ path += "/configuration"
qualifier = input_data.get("Qualifier")
if qualifier is not None:
query_params["Qualifier"] = str(qualifier)
@@ -4414,7 +4419,7 @@ def _dispatch_aws_sdk_lambda_rest(service_info, service_name, action, input_data
"States.Runtime",
f"aws-sdk:{service_name}:{action} is not yet implemented in MiniStack "
"(lambda REST dispatcher covers createFunction, updateFunctionConfiguration, "
- "updateFunctionCode, createAlias, updateAlias, getAlias, and getFunctionConfiguration)",
+ "updateFunctionCode, createAlias, updateAlias, getAlias, getFunction, and getFunctionConfiguration)",
)
# Embed the current SFN execution's account ID as the access-key segment
@@ -4457,7 +4462,15 @@ def _dispatch_aws_sdk_lambda_rest(service_info, service_name, action, input_data
except (json.JSONDecodeError, TypeError):
return decoded
- return _convert_keys_to_sfn_convention(result)
+ output = _convert_keys_to_sfn_convention(result)
+ if pascal_action == "GetFunction" and isinstance(result, dict):
+ # Tags and environment variables are user maps, not SDK member names.
+ if "Tags" in result:
+ output["Tags"] = result["Tags"]
+ environment = result.get("Configuration", {}).get("Environment", {})
+ if "Variables" in environment:
+ output["Configuration"]["Environment"]["Variables"] = environment["Variables"]
+ return output
# ---------------------------------------------------------------------------
diff --git a/tests/test_stepfunctions_service_fidelity.py b/tests/test_stepfunctions_service_fidelity.py
new file mode 100644
index 00000000..c03708d7
--- /dev/null
+++ b/tests/test_stepfunctions_service_fidelity.py
@@ -0,0 +1,121 @@
+"""Exact service integration contracts, based on official AWS API documentation."""
+
+import io
+import json
+import time
+import uuid
+import zipfile
+
+import pytest
+
+
+def _wait(sfn, arn):
+ for _ in range(100):
+ response = sfn.describe_execution(executionArn=arn)
+ if response["status"] != "RUNNING":
+ return response
+ time.sleep(0.1)
+ pytest.fail("execution did not reach a terminal state")
+
+
+def _execute(sfn, state, expected_error):
+ state = dict(state, Catch=[{
+ "ErrorEquals": [expected_error], "ResultPath": "$.caught", "Next": "Recovered",
+ }], End=True)
+ arn = sfn.create_state_machine(
+ name=f"service-fidelity-{uuid.uuid4().hex[:12]}",
+ roleArn="arn:aws:iam::000000000000:role/sfn-role",
+ definition=json.dumps({"StartAt": "Call", "States": {
+ "Call": state, "Recovered": {"Type": "Succeed"},
+ }}),
+ )["stateMachineArn"]
+ try:
+ execution = sfn.start_execution(stateMachineArn=arn, input="{}")
+ return _wait(sfn, execution["executionArn"])
+ finally:
+ sfn.delete_state_machine(stateMachineArn=arn)
+
+
[email protected]("operation", ["putItem", "updateItem", "deleteItem"])
+def test_optimized_dynamodb_conditional_failure_exact_catch(sfn, ddb, operation):
+ """Optimized integration uses DynamoDB.*, not a bare or SDK DynamoDb.* error."""
+ table = f"conditional-{uuid.uuid4().hex[:12]}"
+ ddb.create_table(TableName=table, BillingMode="PAY_PER_REQUEST",
+ KeySchema=[{"AttributeName": "pk", "KeyType": "HASH"}],
+ AttributeDefinitions=[{"AttributeName": "pk", "AttributeType": "S"}])
+ key = {"pk": {"S": "occupied"}}
+ try:
+ ddb.put_item(TableName=table, Item=key)
+ params = {"TableName": table, "ConditionExpression": "attribute_not_exists(pk)"}
+ if operation == "putItem":
+ params["Item"] = key
+ else:
+ params["Key"] = key
+ if operation == "updateItem":
+ params.update(UpdateExpression="SET counter = :v", ExpressionAttributeValues={":v": {"N": "1"}})
+ result = _execute(sfn, {"Type": "Task", "Resource": f"arn:aws:states:::dynamodb:{operation}",
+ "Parameters": params}, "DynamoDB.ConditionalCheckFailedException")
+ assert result["status"] == "SUCCEEDED", result
+ assert json.loads(result["output"])["caught"]["Error"] == "DynamoDB.ConditionalCheckFailedException"
+ assert ddb.get_item(TableName=table, Key=key)["Item"] == key
+ finally:
+ ddb.delete_table(TableName=table)
+
+
+def test_optimized_dynamodb_missing_table_exact_catch(sfn):
+ result = _execute(sfn, {"Type": "Task", "Resource": "arn:aws:states:::dynamodb:getItem",
+ "Parameters": {"TableName": f"missing-{uuid.uuid4().hex[:12]}",
+ "Key": {"pk": {"S": "x"}}}}, "DynamoDB.ResourceNotFoundException")
+ assert result["status"] == "SUCCEEDED", result
+ assert json.loads(result["output"])["caught"]["Error"] == "DynamoDB.ResourceNotFoundException"
+
+
[email protected]("qualifier", [None, "version", "alias"])
+def test_sdk_lambda_get_function_reads_configuration_code_and_literal_maps(sfn_sync, lam, qualifier):
+ suffix = uuid.uuid4().hex[:12]
+ function = f"get-function-{suffix}"
+ tags = {"owner.name": "test", "lower-case": "literal", "UPPER": "unchanged"}
+ variables = {"lowercase": "value", "UPPER": "other"}
+ buffer = io.BytesIO()
+ with zipfile.ZipFile(buffer, "w") as archive:
+ archive.writestr("index.py", "def handler(e, c): return e")
+ lam.create_function(FunctionName=function, Runtime="python3.12", Handler="index.handler",
+ Role="arn:aws:iam::000000000000:role/lambda-role", Code={"ZipFile": buffer.getvalue()},
+ Tags=tags, Environment={"Variables": variables}, Description="published")
+ machine = None
+ try:
+ version = lam.publish_version(FunctionName=function)["Version"]
+ lam.create_alias(FunctionName=function, Name="live", FunctionVersion=version)
+ lam.update_function_configuration(FunctionName=function, Description="latest")
+ params = {"FunctionName": f"arn:aws:lambda:us-east-1:000000000000:function:{function}"}
+ if qualifier is not None:
+ params["Qualifier"] = version if qualifier == "version" else "live"
+ machine = sfn_sync.create_state_machine(
+ name=f"get-function-{suffix}", roleArn="arn:aws:iam::000000000000:role/sfn-role",
+ definition=json.dumps({"StartAt": "Read", "States": {"Read": {
+ "Type": "Task", "Resource": "arn:aws:states:::aws-sdk:lambda:getFunction",
+ "Parameters": params, "End": True,
+ }}}),
+ )["stateMachineArn"]
+ result = sfn_sync.start_sync_execution(stateMachineArn=machine, input="{}")
+ assert result["status"] == "SUCCEEDED", result
+ output = json.loads(result["output"])
+ assert output["Configuration"]["FunctionName"] == function
+ assert output["Configuration"]["Version"] == (version if qualifier else "$LATEST")
+ assert output["Configuration"]["Description"] == ("published" if qualifier else "latest")
+ assert output["Configuration"]["Environment"]["Variables"] == variables
+ assert output["Code"]["Location"]
+ if qualifier is None:
+ assert output["Tags"] == tags
+ finally:
+ if machine:
+ sfn_sync.delete_state_machine(stateMachineArn=machine)
+ lam.delete_function(FunctionName=function)
+
+
+def test_sdk_lambda_get_function_missing_function_exact_catch(sfn):
+ result = _execute(sfn, {"Type": "Task", "Resource": "arn:aws:states:::aws-sdk:lambda:getFunction",
+ "Parameters": {"FunctionName": f"missing-{uuid.uuid4().hex[:12]}"}},
+ "Lambda.ResourceNotFoundException")
+ assert result["status"] == "SUCCEEDED", result
+ assert json.loads(result["output"])["caught"]["Error"] == "Lambda.ResourceNotFoundException"