
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
serverless-dynamodb-local
Advanced tools
npm install --save serverless-dynamodb-local
Then in serverless.yml
add following entry to the plugins array: serverless-dynamodb-local
plugins:
- serverless-dynamodb-local
Install DynamoDB Local
sls dynamodb install
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.
sls dynamodb start
Create/Execute DynamoDB (Migrations)
Create a new migration file (Default directory path /dynamodb). Make sure DynamoDB Local is started in another shell.
sls dynamodb create -n <filename>
Execute a single migration. Make sure DynamoDB Local is started in another shell.
sls dynamodb execute -n <filename>
Execute all migrations for DynamoDB Local.
sls dynamodb executeAll
Note: Read the detailed section for more information on advanced options and configurations. Open a browser and go to the url http://localhost:8000/shell to access the web shell for dynamodb local.
To remove the installed dynamodb local, run:
sls dynamodb remove
Note: This is useful if the sls dynamodb install failed in between to completely remove and install a new copy of DynamoDB local.
All CLI options are optional:
--port -p Port to listen on. Default: 8000
--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.
--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.
--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.
--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.
--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.)
--optimizeDbBeforeStartup -o Optimizes the underlying database tables before starting up DynamoDB on your computer. You must also specify -dbPath when you use this parameter.
--migration -m After starting dynamodb local, run dynamodb migrations.
All the above options can be added to serverless.yml to set default configuration: e.g
custom:
dynamodb:
start:
port: 8000
inMemory: true
migration: true
migration:
dir: ./offline/migrations
In serverless.yml
add following to customize DynamoDB Migrations file directory and table prefixes/suffixes
custom:
dynamodb:
migration:
dir: dynamodbMigrations
table_prefix: prefix
table_suffix": suffix
In serverless.yml
add following to execute all the migration upon DynamoDB Local Start
custom:
dynamodb:
start:
migration: true
{
"Table": {
"TableName": "TableName",
"KeySchema": [{
"AttributeName": "attr_1",
"KeyType": "HASH"
}, {
"AttributeName": "attr_2",
"KeyType": "RANGE"
}],
"AttributeDefinitions": [{
"AttributeName": "attr_1",
"AttributeType": "S"
}, {
"AttributeName": "attr_2",
"AttributeType": "S"
}],
"LocalSecondaryIndexes": [{
"IndexName": "local_index_1",
"KeySchema": [{
"AttributeName": "attr_1",
"KeyType": "HASH"
}, {
"AttributeName": "attr_2",
"KeyType": "RANGE"
}],
"Projection": {
"NonKeyAttributes": ["attr_1", "attr_2"],
"ProjectionType": "INCLUDE"
}
}],
"GlobalSecondaryIndexes": [{
"IndexName": "global_index_1",
"KeySchema": [{
"AttributeName": "attr_1",
"KeyType": "HASH"
}, {
"AttributeName": "attr_2",
"KeyType": "RANGE"
}],
"Projection": {
"NonKeyAttributes": ["attr_1", "attr_2"],
"ProjectionType": "INCLUDE"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
}
}],
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
}
},
"Seeds": [{
"attr_1": "attr_1_value",
"attr_2": "attr_2_value"
}]
}
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.
You need to add the following parameters to the AWS NODE SDK dynamodb constructor
e.g. for dynamodb document client sdk
var AWS = require('aws-sdk');
new AWS.DynamoDB.DocumentClient({
region: 'localhost',
endpoint: 'http://localhost:8000'
})
e.g. for dynamodb document client sdk
new AWS.DynamoDB({
region: 'localhost',
endpoint: 'http://localhost:8000'
})
When using this plugin with serverless-offline, it is difficult to use above syntax since the code should use DynamoDB Local for development, and use DynamoDB Online after provisioning in AWS. Therefore we suggest you to use serverless-dynamodb-client plugin in your code.
FAQs
Serverless dynamodb local plugin
The npm package serverless-dynamodb-local receives a total of 23,806 weekly downloads. As such, serverless-dynamodb-local popularity was classified as popular.
We found that serverless-dynamodb-local demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.