Skip to content

Commit

Permalink
Add SQS Event Info Support (#282)
Browse files Browse the repository at this point in the history
* Add SQS Event Info Support

Closes #243

* Update README
  • Loading branch information
kolanos authored Nov 28, 2018
1 parent cac197f commit b5631ef
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,15 @@ def handler(event, context):

When this plugin is installed, custom metrics will be created automatically for the following event source data:

* Alexa Skill Kit
* API Gateway
* Alexa Skill Kit
* CloudFront
* Kinesis
* Kinesis Firehose
* S3
* SES
* SNS
* SQS
* Scheduled Events

Now in your IOpipe invocation view you will see useful event information.
Expand Down
23 changes: 23 additions & 0 deletions iopipe/contrib/eventinfo/event_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,28 @@ def has_required_keys(self):
)


class SQS(EventType):
type = "sqs"
keys = [
"Records[0].attributes.ApproximateFirstReceiveTimestamp",
"Records[0].attributes.ApproximateReceiveCount",
"Records[0].attributes.SenderId",
"Records[0].attributes.SentTimestamp",
"Records[0].awsRegion",
"Records[0].eventSourceARN",
"Records[0].md5OfBody",
"Records[0].messageId",
"Records[0].receiptHandle",
]
required_keys = ["Records[0].eventSource"]

def has_required_keys(self):
return (
super(SQS, self).has_required_keys()
and get_value(self.event, "Records[0].eventSource") == "aws:sqs"
)


EVENT_TYPES = [
AlexaSkill,
ApiGateway,
Expand All @@ -195,6 +217,7 @@ def has_required_keys(self):
Scheduled,
ServerlessLambda,
SNS,
SQS,
]


Expand Down
5 changes: 5 additions & 0 deletions tests/contrib/eventinfo/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ def event_sns():
return _load_event("sns")


@pytest.fixture
def event_sqs():
return _load_event("sqs")


@pytest.fixture
def event_scheduled():
return _load_event("scheduled")
Expand Down
20 changes: 20 additions & 0 deletions tests/contrib/eventinfo/events/sqs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"Records": [
{
"body": "Hello from SQS!",
"receiptHandle": "MessageReceiptHandle",
"md5OfBody": "7b270e59b47ff90a553787216d55d91d",
"eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:MyQueue",
"eventSource": "aws:sqs",
"awsRegion": "us-east-1",
"messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
"attributes": {
"ApproximateFirstReceiveTimestamp": "1523232000001",
"SenderId": "123456789012",
"ApproximateReceiveCount": "1",
"SentTimestamp": "1523232000000"
},
"messageAttributes": {}
}
]
}
13 changes: 13 additions & 0 deletions tests/contrib/eventinfo/test_event_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,16 @@ def test__event_types__sns(event_sns):
"@iopipe/event-info.sns.%s" % key for key in event.keys
]
assert list(event_info.keys()).sort() == expected_keys.sort()


def test__event_types__sqs(event_sqs):
event = et.SQS(event_sqs)
assert event.has_required_keys() is True

event_info = event.collect()
assert event_info != {}

expected_keys = ["@iopipe/event-info.eventType"] + [
"@iopipe/event-info.sqs.%s" % key for key in event.keys
]
assert list(event_info.keys()).sort() == expected_keys.sort()

0 comments on commit b5631ef

Please sign in to comment.