Last active
April 30, 2019 16:24
-
-
Save thomasmichaelwallace/6614738deda622ffdf41612b246681d2 to your computer and use it in GitHub Desktop.
squirreldex: lambda handler
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
exports.handler = async function (event, context) { | |
// parse the event, get the squirrel, save the world. | |
// (this is javascript, read from the bottom to the top!) | |
const { action } = event || {}; | |
if (action === 'update-squirrel') { | |
// route c: invoked by an admin looking to update an entry on a squirrel. | |
const { id, entry } = event; | |
await db.update(id, entry); | |
return { status: 'super effective' }; | |
} else if (action === 'next-sotd') { | |
// route b: invoked by cloudwatch every night to update set a new squirrel | |
// of the day. | |
await config.updateSotd(); | |
return { status: 'ok' }; | |
} | |
// route a: either return the squirrel with the requested id, | |
// or return the squirrel of the day (SOTD). | |
const { id = process.env.SD_SOTD } = event || {}; | |
const squirrel = db.get(id); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment