Skip to content

Instantly share code, notes, and snippets.

@israelb
Created February 20, 2018 23:49
Show Gist options
  • Save israelb/771a45617331b82e6b23da0f60d07ec8 to your computer and use it in GitHub Desktop.
Save israelb/771a45617331b82e6b23da0f60d07ec8 to your computer and use it in GitHub Desktop.
dynamo localmente
// create table
var params = {
TableName: 'Report',
KeySchema: [
{
AttributeName: 'UserID',
KeyType: 'HASH',
},
],
AttributeDefinitions: [
{
AttributeName: 'UserID',
AttributeType: 'S',
},
],
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5,
},
};
dynamodb.createTable(params, function(err, data) {
if (err) ppJson(err); // an error occurred
else ppJson(data); // successful response
});
// list items
var dynamodb = new AWS.DynamoDB({
region: 'us-east-1',
endpoint: "http://localhost:8000"
});
var tableName = "Report";
var params = {
TableName: tableName,
Select: "ALL_ATTRIBUTES"
};
function doScan(response) {
if (response.error) ppJson(response.error); // an error occurred
else {
ppJson(response.data); // successful response
// More data. Keep calling scan.
if ('LastEvaluatedKey' in response.data) {
response.request.params.ExclusiveStartKey = response.data.LastEvaluatedKey;
dynamodb.scan(response.request.params)
.on('complete', doScan)
.send();
}
}
}
console.log("Starting a Scan of the table");
dynamodb.scan(params)
.on('complete', doScan)
.send();
# server
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment