-
-
Save RoyiNamir/78d0779819409d16ccd4a23b9fbb581b to your computer and use it in GitHub Desktop.
This file contains 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
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