diff --git a/README.md b/README.md index 3d785ca..6cff39e 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Rational defaults are set but can be overridden in the options object. Credentia - `table` Optional DynamoDB server session table name (defaults to "sessions") - `hashKey` Optional hash key (defaults to "id") - `prefix` Optional key prefix (defaults to "sess") + - `payPerRequest` Optional boolean when true will set the billing mode to `PAY_PER_REQUEST` - `reapInterval` Legacy session expiration cleanup in milliseconds. Should instead enable [DynamoDB TTL](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html) and select the `expires` field. **BREAKING CHANGE** from v1.0.11 to v2.0.0 for reaping sessions with changes to the format of the expires field timestamp. ## Usage @@ -42,8 +43,13 @@ Rational defaults are set but can be overridden in the options object. Credentia // Optional ProvisionedThroughput params, defaults to 5 readCapacityUnits: 25, writeCapacityUnits: 25 + + // Optional payPerRequest will set read / write capacity units to 0 + // and Billing Mode to PAY_PER_REQUEST + payPerRequest: false }; + With [connect](https://github.com/senchalabs/connect) var connect = require('connect'); diff --git a/lib/connect-dynamodb.js b/lib/connect-dynamodb.js index 04189e9..887079e 100644 --- a/lib/connect-dynamodb.js +++ b/lib/connect-dynamodb.js @@ -44,6 +44,42 @@ module.exports = function (connect) { this.readCapacityUnits = null == options.readCapacityUnits ? 5 : parseInt(options.readCapacityUnits,10); this.writeCapacityUnits = null == options.writeCapacityUnits ? 5 : parseInt(options.writeCapacityUnits,10); + if (options.payPerRequest) { + this.tableOptions = { + TableName: this.table, + AttributeDefinitions: [{ + AttributeName: this.hashKey, + AttributeType: 'S' + }], + KeySchema: [{ + AttributeName: this.hashKey, + KeyType: 'HASH' + }], + ProvisionedThroughput: { + ReadCapacityUnits: 0, + WriteCapacityUnits: 0 + } + } + } + this.tableOptions = { + TableName: this.table, + AttributeDefinitions: [{ + AttributeName: this.hashKey, + AttributeType: 'S' + }], + KeySchema: [{ + AttributeName: this.hashKey, + KeyType: 'HASH' + }], + ProvisionedThroughput: { + ReadCapacityUnits: this.readCapacityUnits, + WriteCapacityUnits: this.writeCapacityUnits + }, + BillingModeSummary: { + BillingMode: "PAY_PER_REQUEST" + } + } + if (options.client) { this.client = options.client; @@ -70,21 +106,7 @@ module.exports = function (connect) { TableName: this.table }, function (error, info) { if (error) { - this.client.createTable({ - TableName: this.table, - AttributeDefinitions: [{ - AttributeName: this.hashKey, - AttributeType: 'S' - }], - KeySchema: [{ - AttributeName: this.hashKey, - KeyType: 'HASH' - }], - ProvisionedThroughput: { - ReadCapacityUnits: this.readCapacityUnits, - WriteCapacityUnits: this.writeCapacityUnits - } - }, console.log); + this.client.createTable(this.tableOptions, console.log); } }.bind(this)); };