Skip to content

Instantly share code, notes, and snippets.

@dmfranko
Created December 1, 2018 02:42
Show Gist options
  • Save dmfranko/074efde36412e0f66adefaa84920e2d0 to your computer and use it in GitHub Desktop.
Save dmfranko/074efde36412e0f66adefaa84920e2d0 to your computer and use it in GitHub Desktop.
brandeiscloudweek8.js
var AWS = require("aws-sdk");
AWS.config.update({
region: "us-east-1",
endpoint: "dynamodb.us-east-1.amazonaws.com"
});
var docClient = new AWS.DynamoDB.DocumentClient();
// The table I created
var table = "BrandeisClass";
var params = {
TableName: table,
Key:{
"Text": "Another",
}
};
docClient.get(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
// Let's just post some data with some additional fields
var item = {
"Text":"yeah",
"LastUpdate" :
{
"year" : 2014,
"month" : 10,
"day" : 30
},
"Locations" :
[ "US", "CAN", "UK", "SP", "CL" ]
}
var params = {
TableName:table,
Item:item
}
console.log("Adding a new item...");
docClient.put(params, function(err, data) {
if (err) {
console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Added item:", JSON.stringify(data, null, 2));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment