Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
feat(triggers): add support for SQS trigger (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranrib authored Nov 19, 2018
1 parent a54f687 commit f106ee9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/triggers/aws_lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ function createSNSTrigger(event, trigger) {
});
}

/**
* Initializes an event representing a trigger to the lambda caused by SQS
* @param {object} event The event the lambda was triggered with
* @param {proto.event_pb.Event} trigger An Event to initialize as the trigger
*/
function createSQSTrigger(event, trigger) {
const resource = trigger.getResource();
trigger.setId(event.Records[0].messageId);
resource.setName(event.Records[0].eventSourceARN.split(':').slice(-1)[0]);
resource.setOperation('ReceiveMessage');
eventInterface.addToMetadata(trigger, {
'MD5 Of Message Body': event.Records[0].md5OfBody,
'Message Attributes': event.Records[0].attributes,
}, {
'Message Body': event.Records[0].body,
});
}

/**
* Initializes an event representing a trigger to the lambda caused by API Trigger
* @param {object} event The event the lambda was triggered with
Expand Down Expand Up @@ -157,6 +175,7 @@ const resourceTypeToFactoryMap = {
kinesis: createKinesisTrigger,
events: createEventsTrigger,
sns: createSNSTrigger,
sqs: createSQSTrigger,
api_gateway: createAPIGatewayTrigger,
dynamodb: createDynamoDBTrigger,
};
Expand Down

0 comments on commit f106ee9

Please sign in to comment.