Skip to content

Commit 6222016

Browse files
committed
add lru cache and remove usage of all()
1 parent f59de19 commit 6222016

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

datadog_lambda/trigger.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import base64
77
import gzip
8+
from functools import lru_cache
9+
810
import ujson as json
911
from io import BytesIO, BufferedReader
1012
from enum import Enum
@@ -369,6 +371,7 @@ def extract_http_status_code_tag(trigger_tags, response):
369371
return str(status_code)
370372

371373

374+
@lru_cache(maxsize=8)
372375
def is_step_function_event(event):
373376
"""
374377
Check if the event is a step function that invoked the current lambda.
@@ -381,14 +384,15 @@ def is_step_function_event(event):
381384
event = event.get("Payload", event)
382385

383386
# JSONPath style
384-
if all(field in event for field in ("Execution", "StateMachine", "State")):
387+
if "Execution" in event and "StateMachine" in event and "State" in event:
385388
return True
386389

387390
# JSONata style
388-
if "_datadog" in event:
389-
return all(
390-
field in event["_datadog"]
391-
for field in ("Execution", "StateMachine", "State", "serverless-version")
392-
)
393-
394-
return False
391+
dd_context = event.get("_datadog")
392+
return (
393+
dd_context
394+
and "Execution" in dd_context
395+
and "StateMachine" in dd_context
396+
and "State" in dd_context
397+
and "serverless-version" in dd_context
398+
)

0 commit comments

Comments
 (0)