Skip to content

Commit 00b4b9a

Browse files
author
Imran
authored
Merge pull request #1 from Imran99/feature/global_replication
global replication
2 parents 5004845 + 7edf0c9 commit 00b4b9a

File tree

8 files changed

+1794
-0
lines changed

8 files changed

+1794
-0
lines changed

.eslintrc

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"env": {
3+
"es6": true,
4+
"node": true,
5+
"mocha": true
6+
},
7+
"extends": "eslint:recommended",
8+
"parserOptions": {
9+
"ecmaVersion": 2017
10+
},
11+
"rules": {
12+
"indent": [
13+
"error",
14+
2
15+
],
16+
"linebreak-style": [
17+
"error",
18+
"unix"
19+
],
20+
"quotes": [
21+
"error",
22+
"single"
23+
],
24+
"semi": [
25+
"error",
26+
"always"
27+
],
28+
"no-unused-vars": [
29+
"error"
30+
],
31+
"prefer-const": [
32+
"error",
33+
{
34+
"destructuring": "all"
35+
}
36+
],
37+
"no-console": "off"
38+
}
39+
}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.serverless

.vscode/launch.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Run tests",
6+
"type": "node",
7+
"request": "launch",
8+
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
9+
"args": [
10+
"test/**/*.js",
11+
"-t",
12+
"60000",
13+
"--color"
14+
],
15+
"env": {
16+
"AWS_REGION": "eu-west-2"
17+
},
18+
"cwd": "${workspaceRoot}"
19+
},
20+
]
21+
}

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Serverless Create DynamoDB Global Tables For CF Stack
2+
3+
A Serverless plugin that will add a global table and replica region for all tables deployed in a serverless stack.
4+
5+
DynamoDB currently imposes some strict limitations when [creating global tables](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/globaltables_reqs_bestpractices.html):
6+
- The table provisioning settings must match for each regional table
7+
- The table names must match
8+
- Streams must be enabled
9+
- All tables must be empty
10+
- If a replica table is removed from a global table it can not be added again. You can however drop the table and recreate it to add it to global replication.
11+
12+
The plugin handles these limitation by enabling global replication for all tables defined in the serverless stack and thus tying the global tables lifecycle to the table resources defined in the stack. Adding and removing tables from the stack will add and remove them from replication.
13+
14+
## Install
15+
16+
```sh
17+
$ npm install serverless-create-dynamodb-global-tables-for-cf-stack --save-dev
18+
```
19+
20+
Add the plugin to your `serverless.yml` file:
21+
22+
```yml
23+
plugins:
24+
- serverless-create-dynamodb-global-tables-for-cf-stack
25+
```
26+
27+
## Usage
28+
29+
Simply deploy your stack to each region you wish to add to the replication group. Remove your stack from each region that you no longer want in replication.
30+
31+
```sh
32+
serverless deploy --region us-east-1
33+
serverless deploy --region eu-west-1
34+
```
35+
36+
When you add/remove table resources from your serverless stack they will also be added/removed from global replication but you will need to redeploy your stack to each region.
37+
38+
## Disabling
39+
40+
The plugin is enabled by default. You can disable the plugin via config. You may want to do this in certain environments for example.
41+
42+
```yml
43+
custom:
44+
createDynamoDBGlobalTables:
45+
enabled: ${self:custom.variables.${self:custom.variables.stage}.enabled}
46+
```
47+
48+
Disabling the plugin after deploying the stack will have no effect on global tables that were previously deployed. This is due to the previously mentioned limitations of dyanmodb global tables.

0 commit comments

Comments
 (0)