Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added way to set the table to pay per request #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down
52 changes: 37 additions & 15 deletions lib/connect-dynamodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't update the document to tell the user that if they want on-demand, set the value to z0

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;
Expand All @@ -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));
};
Expand Down