Created
March 20, 2019 20:46
-
-
Save nason/3f9ca2c1626d0da7882fc09cf7af6ac4 to your computer and use it in GitHub Desktop.
Revisions
-
nason created this gist
Mar 20, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ async function handleInsert(record) {} async function handleUpdate(record) {} async function handleRemove(record) {} async function receiveHandler(event, context, callback) { const results = await Promise.all( event.Records.map(record => { console.log(JSON.stringify(record)); switch (record.eventName) { case 'INSERT': return handleInsert(record); case 'MODIFY': return handleUpdate(record); case 'REMOVE': return handleRemove(record); default: console.error('Unknown Event'); console.log(JSON.stringify(record)); // Return, not throw, so stream processing continues // If an error is thrown from this handler, the event will be retried return `Unknown event: ${record.eventName}`; } }) ); console.log(results); return `Successfully processed ${event.Records.length} records.`; }