This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(triggers): adding support for SNS -> SQS triggers (#23)
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @fileoverview SQS utility functions | ||
*/ | ||
|
||
/** | ||
* If exists, gets the SNS message that triggered the SQS, | ||
* and generates event data out of it. | ||
* @param {object} messages The SQS messages object | ||
* @returns {object} SNS event data json | ||
*/ | ||
function getSNSTrigger(messages) { | ||
let foundSnsEvent = null; | ||
messages.some((message) => { | ||
try { | ||
let body = null; | ||
if ('Body' in message) { | ||
body = JSON.parse(message.Body); | ||
} else if ('body' in message) { | ||
body = JSON.parse(message.body); | ||
} else { | ||
return true; | ||
} | ||
|
||
if ('Type' in body && | ||
'MessageId' in body && | ||
'TopicArn' in body && | ||
'Message' in body && | ||
'Timestamp' in body && | ||
'SignatureVersion' in body && | ||
'Signature' in body) { | ||
foundSnsEvent = body; | ||
return true; | ||
} | ||
} catch (ex) { | ||
// Continue to the next message | ||
} | ||
|
||
return true; | ||
}); | ||
|
||
return foundSnsEvent; | ||
} | ||
|
||
module.exports.getSNSTrigger = getSNSTrigger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters