Skip to content

Commit bf757b9

Browse files
authored
fix: separate durable async invoke flow (#8636)
* fix: separate durable async invoke flow * test: mock durable_config to none for od async unit tests
1 parent dea7e5c commit bf757b9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

samcli/local/lambda_service/local_lambda_http_service.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ def _invoke_request_handler(self, function_name):
274274
"function": function,
275275
}
276276

277-
if invocation_type == EVENT:
277+
is_durable = function is not None and function.durable_config is not None
278+
279+
# Non-durable EVENT invocations run fully async
280+
if invocation_type == EVENT and not is_durable:
278281
self.executor.submit(self._invoke_async_lambda, **arguments)
279282
return self.service_response("", headers, 202)
280283
try:
@@ -295,6 +298,10 @@ def _invoke_request_handler(self, function_name):
295298
if invoke_headers and isinstance(invoke_headers, dict):
296299
headers.update(invoke_headers)
297300

301+
# Durable EVENT invocations return 202 with execution ARN header but empty body
302+
if is_durable and invocation_type == EVENT:
303+
return self.service_response("", headers, 202)
304+
298305
if is_lambda_user_error_response:
299306
headers["x-amz-function-error"] = "Unhandled"
300307

tests/unit/local/lambda_service/test_local_lambda_http_service.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ def test_invoke_request_handler_async_invocation_returns_202(
414414
local_lambda_http_service.request = request_mock
415415

416416
lambda_runner_mock = Mock()
417+
lambda_runner_mock.get_function.return_value.durable_config = None
417418
lambda_runner_mock.invoke.return_value = {
418419
"X-Amz-Durable-Execution-Arn": "arn:aws:lambda:us-west-2:123456789012:function:test-function:$LATEST/durable-execution/test-123"
419420
}
@@ -492,6 +493,7 @@ def fake_invoke(*args, **kwargs):
492493
local_lambda_http_service.request = request_mock
493494

494495
lambda_runner_mock = Mock()
496+
lambda_runner_mock.get_function.return_value.durable_config = None
495497
service = LocalLambdaHttpService(lambda_runner=lambda_runner_mock, port=3000, host="localhost")
496498
service._invoke_lambda = fake_invoke
497499
service.create()
@@ -527,6 +529,7 @@ def test_invoke_request_handler_async_invocation_submits_to_executor(
527529
local_lambda_http_service.request = request_mock
528530

529531
lambda_runner_mock = Mock()
532+
lambda_runner_mock.get_function.return_value.durable_config = None
530533
service = LocalLambdaHttpService(lambda_runner=lambda_runner_mock, port=3000, host="localhost")
531534

532535
response = service._invoke_request_handler(function_name="HelloWorld")
@@ -556,6 +559,7 @@ def test_invoke_async_lambda_logs_exceptions(self, executor_class_mock, log_mock
556559
local_lambda_http_service.request = request_mock
557560

558561
lambda_runner_mock = Mock()
562+
lambda_runner_mock.get_function.return_value.durable_config = None
559563
test_exception = Exception("Test async exception")
560564
lambda_runner_mock.invoke.side_effect = test_exception
561565

0 commit comments

Comments
 (0)