Skip to content

Instantly share code, notes, and snippets.

@danilop
Last active April 3, 2018 13:00
Show Gist options
  • Save danilop/2ef9a056211a10c68289eaafed583e36 to your computer and use it in GitHub Desktop.
Save danilop/2ef9a056211a10c68289eaafed583e36 to your computer and use it in GitHub Desktop.
Sample AWS Lambda function showing how to split your business logic from the event handler.
"use strict";
console.log('Loading function');
// Your business logic
function greetingsFor(name) {
console.log('name: ', name);
if ((name == undefined) || (name == '')) {
name = 'World';
}
const greetings = 'Hello ' + name + '!';
console.log('greetings: ', greetings);
return greetings;
}
// Event wrapper
exports.handler = async (event, context) => {
console.log('Received event:',
JSON.stringify(event, null, 2));
return greetingsFor(event.name);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment