diff --git a/iopipe/contrib/eventinfo/event_types.py b/iopipe/contrib/eventinfo/event_types.py index e6fdc4e8..d0e429cc 100644 --- a/iopipe/contrib/eventinfo/event_types.py +++ b/iopipe/contrib/eventinfo/event_types.py @@ -172,13 +172,13 @@ class SNS(EventType): "Records[0].Sns.TopicArn", "Records[0].Sns.Type", ] - required_keys = ["Records[0].eventVersion", "Records[0].eventSource"] + required_keys = ["Records[0].EventVersion", "Records[0].EventSource"] def has_required_keys(self): return ( super(SNS, self).has_required_keys() - and get_value(self.event, "Records[0].eventVersion") == "1.0" - and get_value(self.event, "Records[0].eventSource") == "aws:sns" + and get_value(self.event, "Records[0].EventVersion") == "1.0" + and get_value(self.event, "Records[0].EventSource") == "aws:sns" ) diff --git a/tests/contrib/eventinfo/conftest.py b/tests/contrib/eventinfo/conftest.py index cb5e88d7..79deae39 100644 --- a/tests/contrib/eventinfo/conftest.py +++ b/tests/contrib/eventinfo/conftest.py @@ -53,6 +53,11 @@ def event_kinesis(): return _load_event("kinesis") +@pytest.fixture +def event_sns(): + return _load_event("sns") + + @pytest.fixture def event_scheduled(): return _load_event("scheduled") diff --git a/tests/contrib/eventinfo/events/sns.json b/tests/contrib/eventinfo/events/sns.json new file mode 100644 index 00000000..a884aa1e --- /dev/null +++ b/tests/contrib/eventinfo/events/sns.json @@ -0,0 +1,31 @@ +{ + "Records": [ + { + "EventVersion": "1.0", + "EventSubscriptionArn": "arn:aws:sns:EXAMPLE", + "EventSource": "aws:sns", + "Sns": { + "SignatureVersion": "1", + "Timestamp": "1970-01-01T00:00:00.000Z", + "Signature": "EXAMPLE", + "SigningCertUrl": "EXAMPLE", + "MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e", + "Message": "Hello from SNS!", + "MessageAttributes": { + "Test": { + "Type": "String", + "Value": "TestString" + }, + "TestBinary": { + "Type": "Binary", + "Value": "TestBinary" + } + }, + "Type": "Notification", + "UnsubscribeUrl": "EXAMPLE", + "TopicArn": "arn:aws:sns:EXAMPLE", + "Subject": "TestInvoke" + } + } + ] +} diff --git a/tests/contrib/eventinfo/test_event_types.py b/tests/contrib/eventinfo/test_event_types.py index ebbb391e..ff52b12b 100644 --- a/tests/contrib/eventinfo/test_event_types.py +++ b/tests/contrib/eventinfo/test_event_types.py @@ -84,3 +84,16 @@ def test__event_types__serverless_lambda(event_serverless_lambda): ] ) assert event_info["@iopipe/event-info.eventType.source"] == event.source + + +def test__event_types__sns(event_sns): + event = et.SNS(event_sns) + assert event.has_required_keys() is True + + event_info = event.collect() + assert event_info != {} + + expected_keys = ["@iopipe/event-info.eventType"] + [ + "@iopipe/event-info.sns.%s" % key for key in event.keys + ] + assert list(event_info.keys()).sort() == expected_keys.sort()