Skip to content
This repository has been archived by the owner. It is now read-only.

Commit 1d4889e

Browse files
committed
Initial commit
0 parents  commit 1d4889e

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/
2+
node_modules/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Nordcloud
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Serverless DynamoDB Point-in-time Recovery
2+
3+
A Serverless Plugin for the [Serverless Framework](http://www.serverless.com)
4+
to enable/disable PITR (Point-in-time recovery) for one or more DynamoDB tables on deploy.
5+
6+
## Introduction
7+
8+
This plugin uses DynamoDB API to update the PointInTimeRecoverySpecification
9+
of the specified tables at the time of deployment, allowing to enable or disable point-in-time recovery of the tables.
10+
11+
## Installation and configuration
12+
13+
In your service root, run:
14+
15+
```bash
16+
npm install --save-dev serverless-dynamodb-pitr
17+
```
18+
19+
Add the plugin to `serverless.yml`:
20+
21+
```yml
22+
plugins:
23+
- serverless-dynamodb-pitr
24+
```
25+
26+
## Usage
27+
28+
You can add items under the `custom.pitr` in `serverless.yml`. Required attributes are `tableName` and `enabled`:
29+
30+
```yml
31+
custom:
32+
pitr:
33+
- tableName: someDynamoDBTableName
34+
- enabled: true or false
35+
```
36+
37+
## TODO
38+
39+
* Add tests
40+
41+
## Release History
42+
43+
* 2018/05/02 - v0.1.0 - Initial version
44+
45+
46+
## License
47+
48+
Copyright (c) 2018 [Nordcloud](https://nordcloud.com/), licensed for users and contributors under MIT license.
49+
https://github.com/SC5/serverless-dynamodb-pitr/blob/master/LICENSE

index.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
const AWS = require('aws-sdk')
4+
const Promise = require('bluebird')
5+
6+
class Plugin {
7+
constructor(serverless, options) {
8+
this.serverless = serverless
9+
this.hooks = {
10+
'after:deploy:deploy': this.afterDeploy.bind(this),
11+
}
12+
}
13+
14+
getRegion() {
15+
return this.serverless.getProvider('aws').getRegion()
16+
}
17+
18+
getPitr() {
19+
return this.serverless.service.custom && this.serverless.service.custom.pitr || []
20+
}
21+
22+
processItem(item) {
23+
if (!item.tableName) {
24+
return Promise.reject(new Error('serverless-dynamodb-pitr: "tableName" is missing'))
25+
}
26+
if (item.enabled === undefined) {
27+
return Promise.reject(new Error('serverless-dynamodb-pitr: "enabled" is missing'))
28+
}
29+
const params = {
30+
PointInTimeRecoverySpecification: {
31+
PointInTimeRecoveryEnabled: !!item.enabled
32+
},
33+
TableName: item.tableName
34+
};
35+
const dynamodb = new AWS.DynamoDB({ region: this.getRegion()})
36+
return dynamodb.updateContinuousBackups(params).promise()
37+
.then(() => {
38+
this.serverless.cli.log(`Point-in-time recovery ${(item.enabled) ? 'enabled' : 'disabled'} on ${item.tableName}`)
39+
})
40+
}
41+
42+
afterDeploy() {
43+
Promise.all(
44+
this.getPitr().map(item => this.processItem(item))
45+
)
46+
}
47+
}
48+
49+
module.exports = Plugin;

package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "serverless-dynamodb-pitr",
3+
"version": "0.1.0",
4+
"engines": {
5+
"node": ">=6.0"
6+
},
7+
"description": "Serverless plugin to enable PITR (Point-in-time recovery) for a DynamoDB table on deploy",
8+
"main": "index.js",
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"author": "Karim Amzil (https://nordcloud.com)",
13+
"license": "MIT",
14+
"repository": {
15+
"type": "git",
16+
"url": "git+https://github.com/SC5/serverless-dynamodb-pitr.git"
17+
},
18+
"bugs": {
19+
"url": "https://github.com/SC5/serverless-dynamodb-pitr/issues"
20+
},
21+
"homepage": "https://github.com/SC5/serverless-dynamodb-pitr#readme",
22+
"keywords": [
23+
"serverless framework plugin",
24+
"serverless applications",
25+
"serverless plugins",
26+
"dynamodb",
27+
"pitr",
28+
"point-in-time recovery",
29+
"backups",
30+
"lambda",
31+
"aws",
32+
"aws lambda",
33+
"amazon",
34+
"amazon web services",
35+
"serverless.com"
36+
],
37+
"dependencies": {
38+
"aws-sdk": "^2.214.1",
39+
"bluebird": "^3.5.1"
40+
},
41+
"devDependencies": {
42+
"serverless": "^1.26.1"
43+
}
44+
}

0 commit comments

Comments
 (0)