Skip to content

Commit 6592fcd

Browse files
ref(aws-lambda): Inline records source lookup, drop _TRIGGERS annotation
1 parent 151b3a4 commit 6592fcd

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

‎sentry_sdk/integrations/aws_lambda/_trigger.py‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from typing import TYPE_CHECKING
22

33
if TYPE_CHECKING:
4-
from typing import Any, Optional
4+
from typing import Any
55

66
# `faas.trigger` of each `eventSource` of `Records` or of a top-level `eventSource`.
77
# https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html
8-
_TRIGGERS: "dict[Optional[str], str]" = {
8+
_TRIGGERS = {
99
"aws:sqs": "pubsub",
1010
"aws:sns": "pubsub",
1111
"aws:kinesis": "pubsub",
@@ -37,11 +37,6 @@
3737
)
3838

3939

40-
def _get_records_source(records: "list[Any]") -> "Optional[str]":
41-
"""The records' `eventSource`, one per event; SNS spells it `EventSource`."""
42-
return records[0].get("eventSource") or records[0].get("EventSource")
43-
44-
4540
def _is_appsync_event(aws_event: "Any") -> bool:
4641
# https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference-js.html
4742
return (
@@ -78,7 +73,9 @@ def _get_trigger(aws_event: "Any") -> str:
7873
# CloudFront and Lambda@Edge records have no `eventSource`.
7974
if "cf" in records[0]:
8075
return "http"
81-
return _TRIGGERS.get(_get_records_source(records), "other")
76+
# SNS spells it `EventSource`.
77+
source = records[0].get("eventSource") or records[0].get("EventSource")
78+
return _TRIGGERS.get(source, "other")
8279

8380
if _EVENTBRIDGE_KEYS <= aws_event.keys():
8481
if (
@@ -88,4 +85,4 @@ def _get_trigger(aws_event: "Any") -> str:
8885
return "timer"
8986
return "pubsub"
9087

91-
return _TRIGGERS.get(aws_event.get("eventSource"), "other")
88+
return _TRIGGERS.get(aws_event.get("eventSource", ""), "other")

0 commit comments

Comments
 (0)