Skip to content

Instantly share code, notes, and snippets.

@Hiteshm01
Created January 15, 2016 20:20
Show Gist options
  • Save Hiteshm01/ecba65996fa14fc0ec76 to your computer and use it in GitHub Desktop.
Save Hiteshm01/ecba65996fa14fc0ec76 to your computer and use it in GitHub Desktop.
"use strict";
var AWS = require('aws-sdk');
var https = require('https');
var http = require('http');
var keys = {
accessKeyId: 'development',
secretAccessKey: 'development',
region: 'us-east-1',
HISTORY_LOADER_MERCHANTS: [3]
};
var httpsAgent = new https.Agent();
httpsAgent.maxSockets = http.globalAgent.maxSockets*4;
// Run a dynalite server on port 4567
var dynamo = new AWS.DynamoDB({
endpoint: '127.0.0.1:4567',
region: keys.region,
accessKeyId: keys.accessKeyId,
secretAccessKey: keys.secretAccessKey,
maxRetries : 1,
'httpOptions': {
'timeout' : 8*1000, //10 secs
'agent' : httpsAgent
}
});
var hm = {
createTable: function (cb) {
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, function (err, data) {
if (err) {
console.log('Error occurred while creating table ' + params + ' ' + err);
}
if (cb) {
cb(err, data);
}
});
}
};
module.exports = hm;
/*---------------------- TEST CODE ----------------------*/
(function () {
if (require.main === module) {
hm.createTable(console.log);
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment