11from typing import TYPE_CHECKING
22
33if 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" ,
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-
4540def _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