Skip to content

Commit e58b065

Browse files
authored
fix: add typecheck to lambda wrapper (#533)
* check if event is a dict before getting * early exit in is_legacy_lambda_step_function
1 parent 3e92292 commit e58b065

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Diff for: datadog_lambda/tracing.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ def is_legacy_lambda_step_function(event):
411411
"""
412412
Check if the event is a step function that called a legacy lambda
413413
"""
414-
event = event.get("Payload", {})
414+
if not isinstance(event, dict) or "Payload" not in event:
415+
return False
416+
417+
event = event.get("Payload")
415418
return "Execution" in event and "StateMachine" in event and "State" in event
416419

417420

Diff for: tests/test_tracing.py

+3
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,9 @@ def test_is_legacy_lambda_step_function(self):
678678
}
679679
self.assertFalse(is_legacy_lambda_step_function(sf_event))
680680

681+
other_event = ["foo", "bar"]
682+
self.assertFalse(is_legacy_lambda_step_function(other_event))
683+
681684

682685
class TestXRayContextConversion(unittest.TestCase):
683686
def test_convert_xray_trace_id(self):

0 commit comments

Comments
 (0)