Skip to content

Instantly share code, notes, and snippets.

@kinlane
Created October 23, 2017 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kinlane/56880c9282d9e8537a9a5826535c1d79 to your computer and use it in GitHub Desktop.
Save kinlane/56880c9282d9e8537a9a5826535c1d79 to your computer and use it in GitHub Desktop.
addAccount
console.log('Loading event');
var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB();
exports.handler = function(event, context) {
console.log("Request received:\n", JSON.stringify(event));
console.log("Context received:\n", JSON.stringify(context));
var tableName = "accounts";
var datetime = new Date().getTime().toString();
dynamodb.putItem({
"TableName": tableName,
"Item": {
"account_id": {
"S": event.account_id
},
"created": {
"N": datetime
},
"first_name": {
"S": event.first_name
},
"last_name": {
"S": event.last_name
},
"email": {
"S": event.email
},
"description": {
"S": event.description
}
}
}, function(err, data) {
if (err) {
context.fail('ERROR: Dynamo failed: ' + err);
} else {
console.log('Dynamo Success: ' + JSON.stringify(data, null, ' '));
context.succeed('SUCCESS');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment