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
Copy file name to clipboardExpand all lines: README.md
+90-20Lines changed: 90 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ You can use this with ['serverless-offline'](https://github.com/dherault/serverl
17
17
18
18
* Automatically downloads dynamodb local
19
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 local (e.g seeds, tables)
20
+
* Provide you with a set of serverless commands for dynamodb migrations (e.g seeds, tables)
21
21
22
22
## Installation
23
23
@@ -29,7 +29,10 @@ Like this: `"plugins": ["serverless-dynamodb-local"]`
29
29
30
30
## Starting Dynamodb Local
31
31
32
-
In your project root run (Note: Run this command first before any other command, since it will download the dynamodb local during the first run):
32
+
In your project root run (Note: Run this command first before any other command, since it will download the dynamodb local):
33
+
`sls dynamodb install`
34
+
35
+
In your project root run to start dynamodb instance:
33
36
`sls dynamodb start`
34
37
35
38
DynamoDB will process incoming requests until you stop it. To stop DynamoDB, type Ctrl+C in the command prompt window
@@ -38,13 +41,13 @@ All CLI options are optional:
38
41
39
42
```
40
43
--port -p Port to listen on. Default: 8000
41
-
--cors -r Enable CORS support (cross-origin resource sharing) for JavaScript. You must provide a comma-separated "allow" list of specific domains. The default setting for -cors is an asterisk (*), which allows public access.
42
-
--inMemory -m DynamoDB; will run in memory, instead of using a database file. When you stop DynamoDB;, none of the data will be saved. Note that you cannot specify both -dbPath and -inMemory at once.
44
+
--cors -c Enable CORS support (cross-origin resource sharing) for JavaScript. You must provide a comma-separated "allow" list of specific domains. The default setting for -cors is an asterisk (*), which allows public access.
45
+
--inMemory -i DynamoDB; will run in memory, instead of using a database file. When you stop DynamoDB;, none of the data will be saved. Note that you cannot specify both -dbPath and -inMemory at once.
43
46
--dbPath -d The directory where DynamoDB will write its database file. If you do not specify this option, the file will be written to the current directory. Note that you cannot specify both -dbPath and -inMemory at once. For the path, current working directory is <projectroot>/node_modules/serverless-dynamodb-local/dynamob. For example to create <projectroot>/node_modules/serverless-dynamodb-local/dynamob/<mypath> you should specify -d <mypath>/ or --dbPath <mypath>/ with a forwardslash at the end.
44
47
--sharedDb -h DynamoDB will use a single database file, instead of using separate files for each credential and region. If you specify -sharedDb, all DynamoDB clients will interact with the same set of tables regardless of their region and credential configuration.
45
48
--delayTransientStatuses -t Causes DynamoDB to introduce delays for certain operations. DynamoDB can perform some tasks almost instantaneously, such as create/update/delete operations on tables and indexes; however, the actual DynamoDB service requires more time for these tasks. Setting this parameter helps DynamoDB simulate the behavior of the Amazon DynamoDB web service more closely. (Currently, this parameter introduces delays only for global secondary indexes that are in either CREATING or DELETING status.)
46
49
--optimizeDbBeforeStartup -o Optimizes the underlying database tables before starting up DynamoDB on your computer. You must also specify -dbPath when you use this parameter.
47
-
--create -c After starting dynamodb local, create dynamodb tables and run seeds. Check the "Manage tables and seeds" section for more information.
50
+
--migration-m After starting dynamodb local, run dynamodb migrations.
48
51
```
49
52
50
53
All the above options can be added to s-project.json to set default configuration: e.g
@@ -55,7 +58,7 @@ All the above options can be added to s-project.json to set default configuratio
55
58
"start": {
56
59
"port": "8000",
57
60
"inMemory": true,
58
-
"create": true
61
+
"migration": true
59
62
}
60
63
}
61
64
}
@@ -64,43 +67,114 @@ All the above options can be added to s-project.json to set default configuratio
64
67
To remove the installed dynamodb local, run:
65
68
`sls dynamodb remove`
66
69
67
-
## Manage tables and seeds
70
+
## Manage migrations
68
71
69
-
Start dynamodb local instance in another window before running the following commands. To store your dynamodb table creation and seed configurations do the following configuration (If not specified default directory <project-root>/dynamodb)
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)
70
73
71
74
```json
72
75
"custom": {
73
76
"dynamodb": {
74
-
"table": {
77
+
"migration": {
75
78
"dir": "dynamodbTables",
76
-
"prefix": "",
77
-
"suffix": ""
79
+
"table_prefix": "",
80
+
"table_suffix": ""
78
81
}
79
82
}
80
83
}
81
84
```
82
85
83
-
To create table & seed template in your project root, run:
84
-
`sls dynamodb table -n <your-table-name>`
86
+
To create new migration template with the given name, run:
87
+
`sls dynamodb create -n <your-table-name>`
88
+
89
+
To execute a migration template with the given name, run:
90
+
`sls dynamodb execute -n <your-table-name>`
91
+
92
+
To execute all migration templates, run:
93
+
`sls dynamodb executeAll`
94
+
95
+
## Migration Template
96
+
97
+
```json
98
+
{
99
+
"Table": {
100
+
"TableName": "TableName",
101
+
"KeySchema": [{
102
+
"AttributeName": "attr_1",
103
+
"KeyType": "HASH"
104
+
}, {
105
+
"AttributeName": "attr_2",
106
+
"KeyType": "RANGE"
107
+
}],
108
+
"AttributeDefinitions": [{
109
+
"AttributeName": "attr_1",
110
+
"AttributeType": "S"
111
+
}, {
112
+
"AttributeName": "attr_2",
113
+
"AttributeType": "S"
114
+
}],
115
+
"LocalSecondaryIndexes": [{
116
+
"IndexName": "local_index_1",
117
+
"KeySchema": [{
118
+
"AttributeName": "attr_1",
119
+
"KeyType": "HASH"
120
+
}, {
121
+
"AttributeName": "attr_2",
122
+
"KeyType": "RANGE"
123
+
}],
124
+
"Projection": {
125
+
"NonKeyAttributes": ["attr_1", "attr_2"],
126
+
"ProjectionType": "INCLUDE"
127
+
}
128
+
}],
129
+
"GlobalSecondaryIndexes": [{
130
+
"IndexName": "global_index_1",
131
+
"KeySchema": [{
132
+
"AttributeName": "attr_1",
133
+
"KeyType": "HASH"
134
+
}, {
135
+
"AttributeName": "attr_2",
136
+
"KeyType": "RANGE"
137
+
}],
138
+
"Projection": {
139
+
"NonKeyAttributes": ["attr_1", "attr_2"],
140
+
"ProjectionType": "INCLUDE"
141
+
},
142
+
"ProvisionedThroughput": {
143
+
"ReadCapacityUnits": 1,
144
+
"WriteCapacityUnits": 1
145
+
}
146
+
}],
147
+
"ProvisionedThroughput": {
148
+
"ReadCapacityUnits": 1,
149
+
"WriteCapacityUnits": 1
150
+
}
151
+
},
152
+
"Seeds": [{
153
+
"attr_1": "attr_1_value",
154
+
"attr_2": "attr_2_value"
155
+
}]
156
+
}
157
+
```
158
+
Before modifying the migration template, refer the Dynamodb Client SDK and Dynamodb Document Client SDK links.
85
159
86
160
This will create a template json inside configured directory. Open the file and edit the table schema and data.
To create table & run the seeds in your project root, run:
93
167
`sls dynamodb table -c`
94
168
95
169
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
96
170
97
-
Optionally if you want to create the tables and run the seeds on dynamodb starts, use the argument -c or add the "create": true inside s-project.json as shown below
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
98
172
99
173
```json
100
174
"custom": {
101
175
"dynamodb": {
102
176
"start": {
103
-
"create": true
177
+
"migration": true
104
178
}
105
179
}
106
180
}
@@ -160,10 +234,6 @@ sls dynamodb start
160
234
```
161
235
* Go to dynamodb local [shell](http://localhost:8000/shell) in your browser and you should be able to see use the web shell
162
236
163
-
## Credits
164
-
165
-
Bunch of thanks to doapp-ryanp who started [dynamodb-local](https://github.com/doapp-ryanp/dynamodb-local) project
0 commit comments