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
+36-2Lines changed: 36 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,8 @@ All CLI options are optional:
52
52
--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.
53
53
--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.)
54
54
--optimizeDbBeforeStartup -o Optimizes the underlying database tables before starting up DynamoDB on your computer. You must also specify -dbPath when you use this parameter.
55
-
--migrate -m After starting DynamoDB local, create DynamoDB tables from the Serverless configuration..
55
+
--migrate -m After starting DynamoDB local, create DynamoDB tables from the Serverless configuration.
56
+
--seed -s After starting and migrating dynamodb local, injects seed data into your tables. The --seed option determines which data categories to onload.
56
57
```
57
58
58
59
All the above options can be added to serverless.yml to set default configuration: e.g.
@@ -64,10 +65,11 @@ custom:
64
65
port: 8000
65
66
inMemory: true
66
67
migrate: true
68
+
seed: true
67
69
```
68
70
69
71
## Migrations: sls dynamodb migrate
70
-
### Configurations
72
+
### Configuration
71
73
In `serverless.yml` add following to execute all the migration upon DynamoDB Local Start
72
74
```yml
73
75
custom:
@@ -94,6 +96,38 @@ resources:
94
96
WriteCapacityUnits: 1
95
97
```
96
98
99
+
## Seeding: sls dynamodb seed
100
+
### Configuration
101
+
102
+
In `serverless.yml` seeding categories are defined under `dynamodb.seed`.
103
+
104
+
If `dynamodb.start.seed` is true, then seeding is performed after table migrations.
105
+
106
+
```yml
107
+
dynamodb:
108
+
start:
109
+
seed: true
110
+
111
+
seed:
112
+
domain:
113
+
sources:
114
+
- table: domain-widgets
115
+
sources: [./domainWidgets.json]
116
+
- table: domain-fidgets
117
+
sources: [./domainFidgets.json]
118
+
test:
119
+
sources:
120
+
- table: users
121
+
sources: [./fake-test-users.json]
122
+
- table: subscriptions
123
+
sources: [./fake-test-subscriptions.json]
124
+
```
125
+
126
+
```bash
127
+
> sls dynamodb seed --seed=domain,test
128
+
> sls dynamodb start --seed=domain,test
129
+
```
130
+
97
131
## Using DynamoDB Local in your code
98
132
You need to add the following parameters to the AWS NODE SDK dynamodb constructor
usage: 'Creates local DynamoDB tables from the current Serverless configuration'
20
+
lifecycleEvents: ["migrateHandler"],
21
+
usage: "Creates local DynamoDB tables from the current Serverless configuration"
22
+
},
23
+
seed: {
24
+
lifecycleEvents: ["seedHandler"],
25
+
usage: "Seeds local DynamoDB tables with data"
21
26
},
22
27
start: {
23
-
lifecycleEvents: ['startHandler'],
24
-
usage: 'Starts local DynamoDB',
28
+
lifecycleEvents: ["startHandler"],
29
+
usage: "Starts local DynamoDB",
25
30
options: {
26
31
port: {
27
-
shortcut: 'p',
28
-
usage: 'The port number that DynamoDB will use to communicate with your application. If you do not specify this option, the default port is 8000'
32
+
shortcut: "p",
33
+
usage: "The port number that DynamoDB will use to communicate with your application. If you do not specify this option, the default port is 8000"
29
34
},
30
35
cors: {
31
-
shortcut: 'c',
32
-
usage: '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.'
36
+
shortcut: "c",
37
+
usage: "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."
33
38
},
34
39
inMemory: {
35
-
shortcut: 'i',
36
-
usage: '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.'
40
+
shortcut: "i",
41
+
usage: "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."
37
42
},
38
43
dbPath: {
39
-
shortcut: 'd',
40
-
usage: '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
+
shortcut: "d",
45
+
usage: "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."
41
46
},
42
47
sharedDb: {
43
-
shortcut: 'h',
44
-
usage: '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.'
48
+
shortcut: "h",
49
+
usage: "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
50
},
46
51
delayTransientStatuses: {
47
-
shortcut: 't',
48
-
usage: '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.'
52
+
shortcut: "t",
53
+
usage: "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."
49
54
},
50
55
optimizeDbBeforeStartup: {
51
-
shortcut: 'o',
52
-
usage: 'Optimizes the underlying database tables before starting up DynamoDB on your computer. You must also specify -dbPath when you use this parameter.'
56
+
shortcut: "o",
57
+
usage: "Optimizes the underlying database tables before starting up DynamoDB on your computer. You must also specify -dbPath when you use this parameter."
53
58
},
54
59
migrate: {
55
-
shortcut: 'm',
56
-
usage: 'After starting dynamodb local, create DynamoDB tables from the current serverless configuration'
60
+
shortcut: "m",
61
+
usage: "After starting dynamodb local, create DynamoDB tables from the current serverless configuration."
62
+
},
63
+
seed: {
64
+
shortcut: "s",
65
+
usage: "After starting and migrating dynamodb local, injects seed data into your tables. The --seed option determines which data categories to onload.",
57
66
}
58
67
}
59
68
},
60
69
remove: {
61
-
lifecycleEvents: ['removeHandler'],
62
-
usage: 'Removes local DynamoDB'
70
+
lifecycleEvents: ["removeHandler"],
71
+
usage: "Removes local DynamoDB"
63
72
},
64
73
install: {
65
-
usage: 'Installs local DynamoDB',
66
-
lifecycleEvents: ['installHandler'],
74
+
usage: "Installs local DynamoDB",
75
+
lifecycleEvents: ["installHandler"],
67
76
options: {
68
77
localPath: {
69
-
shortcut: 'x',
70
-
usage: 'Local dynamodb install path'
78
+
shortcut: "x",
79
+
usage: "Local dynamodb install path"
71
80
}
72
81
}
73
82
@@ -77,23 +86,29 @@ class ServerlessDynamodbLocal {
0 commit comments