Skip to content

Instantly share code, notes, and snippets.

@satour
Last active November 22, 2016 09:36
Show Gist options
  • Save satour/8b628f5f02dc7aa493043cafef712d3c to your computer and use it in GitHub Desktop.
Save satour/8b628f5f02dc7aa493043cafef712d3c to your computer and use it in GitHub Desktop.
//AWS Lambda function
//required environment variables:["tableName"]
'use strict';
console.log('Loading function');
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
exports.handler = (event, context, callback) => {
console.log('Received event:', JSON.stringify(event, null, 2));
const done = (err, res) => callback(null, {
statusCode: err ? '400' : '200',
body: err ? err.message : JSON.stringify(res),
headers: {
'Content-Type': 'application/json',
},
});
var DynamoRequest = {
"TableName": process.env.tableName,
"Item" : {
"timestamp": new Date().getTime(),
"payload": JSON.stringify(event.body)
}
};
dynamo.putItem(DynamoRequest, done);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment