Created
July 10, 2017 23:51
-
-
Save CollectiveHealth-gists/d21c2b34e149655d31004a3a883c013c to your computer and use it in GitHub Desktop.
Development and Deployment of AWS Lambda Functions: A function to list users in the infrastructure
This file contains hidden or 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
var assert = require('assert'); | |
exports.handler = function(event, context) { | |
// Log the context, it contains details about the function's execution | |
console.log("Context: %j", context); | |
// Log the event, it contains data and parameters passed to the function | |
console.log("Event: %j",event); | |
try { | |
// Simple example to show that the assert library was successfully included | |
assert.strictEqual(typeof context, "object", "context is not a valid object"); | |
} catch(e) { | |
// Catch the assertion error, and fail the method's execution | |
console.error(e); | |
context.fail(e); | |
return; | |
} | |
// Create a static representation of our users, and return that | |
var payload = { | |
"10000001": { | |
"name": "Bruce Wayne", | |
"email": "[email protected]" | |
}, | |
"10000002": { | |
"name": "Harvey Dent", | |
"email": "[email protected]", | |
}, | |
"10000003": { | |
"name": "Lucius Fox", | |
"email": "[email protected]" | |
} | |
}; | |
// If the event has a name and email in it, add it to the returned payload | |
if(event.name !== undefined && event.email !== undefined) { | |
payload["10000004"] = { | |
"name": event.name, | |
"email": event.email | |
}; | |
} | |
// Send the payload back | |
context.succeed(payload); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment