You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This Serverless 0.5.x plugin help you to setup dynamodb local instance with much needed features to setup your serverless local development environment.
10
-
You can use this with ['serverless-offline'](https://github.com/dherault/serverless-offline) Plugin.
11
-
12
9
## This Plugin Requires
13
10
* Serverless V0.5 or newer
14
11
* Java Runtime Engine (JRE) version 6.x or newer
15
12
16
13
## Features
14
+
* Install DynamoDB Local
15
+
* Start DynamoDB Local with all the parameters supported (e.g port, inMemory, sharedDb)
16
+
* Create, Manage and Execute DynamoDB Migration Scripts(Table Creation/ Data Seeds) for DynamoDB Local and Online
17
17
18
-
* Automatically downloads dynamodb local
19
-
* Allow to specify all the supported parameters in dynamodb local (e.g port, inMemory, sharedDb)
20
-
* Provide you with a set of serverless commands for dynamodb migrations (e.g seeds, tables)
21
-
22
-
## Installation
23
-
18
+
## Install Plugin
24
19
`npm install --save serverless-dynamodb-local`
25
20
26
21
Then in `s-project.json` add following entry to the plugins array: `serverless-dynamodb-local`
22
+
e.g `"plugins": ["serverless-dynamodb-local"]`
27
23
28
-
Like this: `"plugins": ["serverless-dynamodb-local"]`
29
-
30
-
## Starting Dynamodb Local
31
-
32
-
In your project root run (Note: Run this command first before any other command, since it will download the dynamodb local):
24
+
## Using the Plugin
25
+
1) Install DynamoDB Local
33
26
`sls dynamodb install`
34
27
35
-
In your project root run to start dynamodb instance:
28
+
2) Start DynamoDB Local (DynamoDB will process incoming requests until you stop it. To stop DynamoDB, type Ctrl+C in the command prompt window). Make sure above command is executed before this.
36
29
`sls dynamodb start`
37
30
38
-
DynamoDB will process incoming requests until you stop it. To stop DynamoDB, type Ctrl+C in the command prompt window
31
+
3) Create/Execute DynamoDB (Migrations)
32
+
* Create a new migration file (Default directory path /dynamodb). Make sure DynamoDB Local is started in another shell.
33
+
`sls dynamodb create -n <filename>`
34
+
35
+
* Execute a single migration. Make sure DynamoDB Local is started in another shell.
36
+
`sls dynamodb execute -n <filename>`
37
+
38
+
* Execute all migrations for DynamoDB Local.
39
+
`sls dynamodb executeAll`
39
40
41
+
* Execute migration(s) in remote DynamoDB use additional parameters(region and stage) after execute/executeAll. e.g.
42
+
`sls dynamodb executeAll -r us-west-1 -s dev`
43
+
44
+
Note: Read the detailed section for more information on advanced options and configurations
45
+
46
+
## Install: `sls dynamodb install`
47
+
To remove the installed dynamodb local, run:
48
+
`sls dynamodb remove`
49
+
50
+
## Start: `sls dynamodb start`
40
51
All CLI options are optional:
41
52
42
53
```
@@ -64,39 +75,32 @@ All the above options can be added to s-project.json to set default configuratio
64
75
}
65
76
```
66
77
67
-
To remove the installed dynamodb local, run:
68
-
`sls dynamodb remove`
69
-
70
-
## Manage Migrations
71
-
72
-
Start dynamodb local instance in another window before running the following commands. To store your dynamodb migration templates do the following configuration (If not specified default directory <project-root>/dynamodb is used)
73
-
78
+
## Create/Execute DynamoDB (Migrations)
79
+
### Configurations
80
+
In `s-project.json` add following to customize DynamoDB Migrations file directory and table prefixes/suffixes
74
81
```json
75
82
"custom": {
76
83
"dynamodb": {
77
84
"migration": {
78
-
"dir": "dynamodbTables",
85
+
"dir": "dynamodbMigrations",
79
86
"table_prefix": "",
80
87
"table_suffix": ""
81
88
}
82
89
}
83
90
}
84
91
```
85
92
86
-
To create new migration template with the given name, run:
87
-
`sls dynamodb create -n <migration-name>`
88
-
89
-
To execute a migration template with the given name, run:
90
-
`sls dynamodb execute -n <migration-file-name>`
91
-
92
-
To execute all migration templates, run:
93
-
`sls dynamodb executeAll`
94
-
95
-
Note: Optionally to execute/executeAll migrations on remote dynamodb, use -r <region> and -s <stage> parameters
96
-
'sls dynamodb executeAll -r us-west-1 -s dev'
97
-
98
-
## Migration Template
99
-
93
+
In `s-project.json` add following to execute all the migration upon DynamoDB Local Start
94
+
```json
95
+
"custom": {
96
+
"dynamodb": {
97
+
"start": {
98
+
"migration": true
99
+
}
100
+
}
101
+
}
102
+
```
103
+
### Migration Template
100
104
```json
101
105
{
102
106
"Table": {
@@ -158,31 +162,10 @@ Note: Optionally to execute/executeAll migrations on remote dynamodb, use -r <re
158
162
}]
159
163
}
160
164
```
161
-
Before modifying the migration template, refer the Dynamodb Client SDK and Dynamodb Document Client SDK links.
162
-
163
-
This will create a template json inside configured directory. Open the file and edit the table schema and data.
If you need to prefix_<your-table-name>_suffix, you can configure the values accordingly. This is usefull when you have multiple stages which needs multiple database tables
170
-
171
-
Optionally if you want to execute all migrations on dynamodb starts, use the argument -m or add the "migration": true inside s-project.json as shown below
172
-
173
-
```json
174
-
"custom": {
175
-
"dynamodb": {
176
-
"start": {
177
-
"migration": true
178
-
}
179
-
}
180
-
}
181
-
```
165
+
Before modifying the migration template, refer the (Dynamodb Client SDK): http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#createTable-property and (Dynamodb Document Client SDK): http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#put-property links.
182
166
183
-
## Using in code
184
-
185
-
You need to add the following parameters to the AWS SDK dynamodb constructor
167
+
## Using DynamoDB Local in your code
168
+
You need to add the following parameters to the AWS NODE SDK dynamodb constructor
186
169
187
170
e.g. for dynamodb document client sdk
188
171
```
@@ -200,40 +183,12 @@ new AWS.DynamoDB({
200
183
201
184
```
202
185
Open a browser and go to the url http://localhost:8000/shell to access the web shell for dynamodb local
203
-
204
186
Note: Default port: 8000 and if you change the port, change it accordingly in usage
205
187
206
188
## Links
207
-
208
189
*[Dynamodb local documentation](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html)
We love our contributors! If you'd like to contribute to the project, feel free to submit a PR. But please keep in mind the following guidelines:
215
-
216
-
* Propose your changes before you start working on a PR. You can reach us by submitting a Github issue. This is just to make sure that no one else is working on the same change, and to figure out the best way to solve the issue.
217
-
* If you're out of ideas, but still want to contribute, help us in solving Github issues already verified.
218
-
* Contributions are not just PRs! We'd be grateful for having you, and if you could provide some support for new comers, that be great! You can also do that by answering this plugin related questions on Stackoverflow.
219
-
You can also contribute by writing. Feel free to let us know if you want to publish a useful guides, improve the documentation (attributed to you, thank you!) that you feel will help the community.
220
-
221
-
## Development Setup
222
-
223
-
* Make a Serverless Project dedicated for plugin development, or use an existing Serverless Project
224
-
* Make a "plugins" folder in the root of your Project and copy this codebase into it. Title it your custom plugin name with the suffix "-dev", like "serverless-dynamodb-local-dev"
225
-
* Go to root of your Project and edit the s-project.json and add
226
-
```
227
-
"plugins": [
228
-
"serverless-dynamodb-local-dev"
229
-
]
230
-
```
231
-
* Open a commandline from your root Project folder and Start a new dynamodb instance by running
232
-
```
233
-
sls dynamodb start
234
-
```
235
-
* Go to dynamodb local [shell](http://localhost:8000/shell) in your browser and you should be able to see use the web shell
0 commit comments