Skip to content

Instantly share code, notes, and snippets.

@RoyiNamir
Created February 16, 2019 14:24
Show Gist options
  • Save RoyiNamir/78d0779819409d16ccd4a23b9fbb581b to your computer and use it in GitHub Desktop.
Save RoyiNamir/78d0779819409d16ccd4a23b9fbb581b to your computer and use it in GitHub Desktop.
console.log('Loading function');
var AWS = require('aws-sdk');
var dynamo = new AWS.DynamoDB.DocumentClient();
exports.handler = async (event, context, callback) =>
{
console.log('Received event:', JSON.stringify(event, null, 2));
var operation = event.operation;
if (event.tableName)
{
event.payload.TableName = event.tableName;
}
switch (operation)
{
case 'create':
dynamo.put(event.payload, callback);
break;
case 'read':
dynamo.get(event.payload, callback);
break;
case 'update':
dynamo.update(event.payload, callback);
break;
case 'delete':
dynamo.delete(event.payload, callback);
break;
case 'list':
dynamo.scan(event.payload, callback);
break;
case 'ping':
callback(null, 'pong');
break;
default:
callback('Unknown operation: ${operation}' + JSON.stringify(event));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment