Skip to content

Instantly share code, notes, and snippets.

@michaelwills
Created December 11, 2015 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelwills/99620e52cb20d51df036 to your computer and use it in GitHub Desktop.
Save michaelwills/99620e52cb20d51df036 to your computer and use it in GitHub Desktop.
JAWS (now) serverless/serverless handling of SNS events

@kfreytag responding to @Nopik

Responding to your question from early this morning about SNS-triggered lambdas. In my experience, you only get one message / Record at a time. Here’s my revised JAWS handler wherein I always deal with a JobId

'use strict';
// from @kfreytag on guitar #serverless/serverless
require('jaws-core-js/env');
// Modularized Code
var action = require('./index.js');
// Lambda Handler
module.exports.handler = function(event, context) {
if ("Records" in event) {
// It's an SNS message;
action.run({ JobId: event.Records[0].Sns.MessageAttributes.JobId.Value }, context, function(error, result) {
return context.done(error, result);
});
} else {
action.run(event, context, function(error, result) {
return context.done(error, result);
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment