Skip to content

Commit

Permalink
using onDemand pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
eahefnawy committed Jul 19, 2019
1 parent 4837606 commit 1204dff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@serverless/aws-dynamodb",
"version": "1.0.0",
"version": "2.0.0",
"main": "./serverless.js",
"publishConfig": {
"access": "public"
Expand Down
4 changes: 0 additions & 4 deletions serverless.js
Expand Up @@ -18,10 +18,6 @@ const defaults = {
KeyType: 'HASH'
}
],
provisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
},
region: 'us-east-1'
}

Expand Down
30 changes: 10 additions & 20 deletions utils.js
@@ -1,18 +1,12 @@
const { not, equals, pick } = require('ramda')

async function createTable({
dynamodb,
name,
attributeDefinitions,
keySchema,
provisionedThroughput
}) {
async function createTable({ dynamodb, name, attributeDefinitions, keySchema }) {
const res = await dynamodb
.createTable({
TableName: name,
AttributeDefinitions: attributeDefinitions,
KeySchema: keySchema,
ProvisionedThroughput: provisionedThroughput
BillingMode: 'PAY_PER_REQUEST'
})
.promise()
return res.TableDescription.TableArn
Expand All @@ -23,13 +17,11 @@ async function describeTable({ dynamodb, name }) {

try {
const data = await dynamodb.describeTable({ TableName: name }).promise()
const table = data.Table
res = {
arn: table.TableArn,
name: table.TableName,
attributeDefinitions: table.AttributeDefinitions,
keySchema: table.KeySchema,
provisionedThroughput: table.ProvisionedThroughput
arn: data.Table.TableArn,
name: data.Table.TableName,
attributeDefinitions: data.Table.AttributeDefinitions,
keySchema: data.Table.KeySchema
}
} catch (error) {
if (error.code === 'ResourceNotFoundException') {
Expand All @@ -40,12 +32,12 @@ async function describeTable({ dynamodb, name }) {
}
}

async function updateTable({ dynamodb, name, attributeDefinitions, provisionedThroughput }) {
async function updateTable({ dynamodb, name, attributeDefinitions }) {
const res = await dynamodb
.updateTable({
TableName: name,
AttributeDefinitions: attributeDefinitions,
ProvisionedThroughput: provisionedThroughput
BillingMode: 'PAY_PER_REQUEST'
})
.promise()
return res.TableDescription.TableArn
Expand All @@ -68,10 +60,8 @@ async function deleteTable({ dynamodb, name }) {
}

function configChanged(prevTable, table) {
const prevInputs = pick(['name', 'attributeDefinitions', 'provisionedThroughput'], prevTable)
const inputs = pick(['name', 'attributeDefinitions', 'provisionedThroughput'], table)

delete prevInputs.provisionedThroughput.NumberOfDecreasesToday
const prevInputs = pick(['name', 'attributeDefinitions'], prevTable)
const inputs = pick(['name', 'attributeDefinitions'], table)

return not(equals(inputs, prevInputs))
}
Expand Down

0 comments on commit 1204dff

Please sign in to comment.