Skip to content

Instantly share code, notes, and snippets.

@nason
Created March 20, 2019 20:46
Show Gist options
  • Save nason/3f9ca2c1626d0da7882fc09cf7af6ac4 to your computer and use it in GitHub Desktop.
Save nason/3f9ca2c1626d0da7882fc09cf7af6ac4 to your computer and use it in GitHub Desktop.
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.`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment