Skip to content

Instantly share code, notes, and snippets.

@mhart
Forked from Hiteshm01/dynalite_test.js
Created January 15, 2016 20:53
Show Gist options
  • Save mhart/9141848bcc34ba9d9d8a to your computer and use it in GitHub Desktop.
Save mhart/9141848bcc34ba9d9d8a to your computer and use it in GitHub Desktop.
var AWS = require('aws-sdk')
var dynamo = new AWS.DynamoDB({endpoint: 'http://localhost:4567'})
var params = {
AttributeDefinitions: [ // required
{
AttributeName: 'test_id', // required
AttributeType: 'N' // required
}, {
AttributeName: 'date', // required
AttributeType: 'N' // required
}, {
AttributeName: 'second_id', // required
AttributeType: 'N' // required
}, {
AttributeName: 'date', // required
AttributeType: 'S' // required
}
],
KeySchema: [{
AttributeName: 'test_id', // required
KeyType: 'HASH' // required
}, {
AttributeName: 'date', // required
KeyType: 'RANGE' // required
}],
ProvisionedThroughput: { // required
ReadCapacityUnits: 5, // required
WriteCapacityUnits: 5 // required
},
TableName: 'history',
GlobalSecondaryIndexes: [{
IndexName: 'date-second_id-index',
KeySchema: [ // required
{
AttributeName: 'date', // required
KeyType: 'HASH' // required
}, {
AttributeName: 'second_id', // required
KeyType: 'RANGE' // required
}
// ... more items ...
],
Projection: { // required
ProjectionType: 'ALL'
},
ProvisionedThroughput: { // required
ReadCapacityUnits: 5, // required
WriteCapacityUnits: 5 // required
}
}]
}
dynamo.createTable(params, console.log.bind(console))
/*
null { TableDescription:
{ AttributeDefinitions: [ [Object], [Object], [Object], [Object] ],
TableName: 'history',
KeySchema: [ [Object], [Object] ],
TableStatus: 'CREATING',
CreationDateTime: Fri Jan 15 2016 15:53:16 GMT-0500 (EST),
ProvisionedThroughput:
{ NumberOfDecreasesToday: 0,
ReadCapacityUnits: 5,
WriteCapacityUnits: 5 },
TableSizeBytes: 0,
ItemCount: 0,
TableArn: 'arn:aws:dynamodb:us-east-1:686281923970:table/history',
GlobalSecondaryIndexes: [ [Object] ] } }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment