Skip to content
This repository was archived by the owner on Jun 4, 2019. It is now read-only.

Commit 396be37

Browse files
sammarkssbstjn
authored andcommitted
Use the built-in getProvider() and region. (#12)
1 parent 7c44fa9 commit 396be37

File tree

4 files changed

+181
-190
lines changed

4 files changed

+181
-190
lines changed

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
"url": "https://github.com/Jimdo/serverless-dynamodb-ttl/issues"
2727
},
2828
"homepage": "https://github.com/Jimdo/serverless-dynamodb-ttl#readme",
29-
"dependencies": {
30-
"aws-sdk": "^2.45.0"
31-
},
29+
"dependencies": {},
3230
"standard": {
3331
"envs": [
3432
"node",
@@ -40,10 +38,10 @@
4038
]
4139
},
4240
"devDependencies": {
43-
"aws-sdk-mock": "^1.7.0",
4441
"coveralls": "^2.13.0",
4542
"dot-json": "^1.0.3",
4643
"jest": "^19.0.2",
44+
"sinon": "^2.3.2",
4745
"snazzy": "^7.0.0",
4846
"standard": "^10.0.2"
4947
}

src/plugin.js

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
const assert = require('assert')
44
const util = require('util')
5-
const AWS = require('aws-sdk')
65

76
class Plugin {
87
constructor (serverless, options) {
98
this.serverless = serverless
109
this.options = options || {}
10+
this.provider = serverless.getProvider('aws')
1111

1212
this.hooks = {
1313
'after:deploy:deploy': this.afterDeploy.bind(this)
@@ -26,23 +26,11 @@ class Plugin {
2626
assert(this.list().length > 0, 'No configuration found')
2727
}
2828

29-
configure () {
30-
this.region = this.serverless.service.provider.region
31-
32-
if (this.options && this.options.region) {
33-
this.region = this.options.region
34-
}
35-
36-
this.dynamodb = new AWS.DynamoDB({ region: this.region })
37-
}
38-
3929
afterDeploy () {
4030
return Promise.resolve().then(
4131
this.validate.bind(this)
4232
).then(
43-
this.configure.bind(this)
44-
).then(
45-
() => this.serverless.cli.log(util.format('Enabling TTL setting(s) for DynamoDB (%s)', this.region))
33+
() => this.serverless.cli.log(util.format('Enabling TTL setting(s) for DynamoDB (%s)', this.options.region))
4634
).then(
4735
() => this.list().map(
4836
data => this.check(data.table).then(
@@ -55,25 +43,21 @@ class Plugin {
5543
}
5644

5745
check (table) {
58-
return this.dynamodb.describeTimeToLive(
59-
{
60-
TableName: table
61-
}
62-
).promise().then(
46+
return this.provider.request('DynamoDB', 'describeTimeToLive', {
47+
TableName: table
48+
}).then(
6349
res => res.TimeToLiveDescription.TimeToLiveStatus === 'ENABLED'
6450
)
6551
}
6652

6753
enable (data) {
68-
return this.dynamodb.updateTimeToLive(
69-
{
70-
TableName: data.table,
71-
TimeToLiveSpecification: {
72-
AttributeName: data.field,
73-
Enabled: true
74-
}
54+
return this.provider.request('DynamoDB', 'updateTimeToLive', {
55+
TableName: data.table,
56+
TimeToLiveSpecification: {
57+
AttributeName: data.field,
58+
Enabled: true
7559
}
76-
).promise()
60+
})
7761
}
7862

7963
list () {

0 commit comments

Comments
 (0)