Installing DynamoDb locally

Is available via binaries or docker. Or serverless integrated:

sls dynamodb install

Running DynamoDb locally

Run using java or docker or using sls dynamodb start .

To ignore credentials pass param --shareDb.

There is also other parameters to set credentials, change port etc. Just check:

sls dynamodb start --help

Creation DynamoDb tables

npm i --save serverless-dynamodb-local

In your serverless.yml

custom:
  dynamodb:
    stages:
      - ${self:provider.stage}

Now create and populate tables form serverless.yml

sls dynamodb migrate

Shell

The web interface for dynamodb

Here are few sample queries

dynamodb.listTables({Limit: 10}, function(err, data) {
  if (err) {
    console.log("Error", err.code);
  } else {
    console.log("Table names are ", data.TableNames);
  }
});
var params = {
    TableName: 'test-table',
    KeyConditionExpression: 'PK = :PK',
    Select: 'ALL_ATTRIBUTES',
    ExpressionAttributeValues: {
        ":PK": "test",
    },
};
docClient.query(params, function(err, data) {
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response
});

Testing

AWS dynamo db client to execute queries from javascript code

const ddb = new DynamoDB.DocumentClient({
	region: 'localhost',
    endpoint: 'http://localhost:8000'
});

Common error during initial setup

    CredentialsError: Missing credentials in configError: connect EHOSTUNREACH 169.254.169.254:80

You still need credentials to access DynamoDB via client. If you specifiaed any accesKey and secretKey during start - use them. If you did not use some placeholder values.

AWS.config.update({
    secretAccessKey: "fakeMyKeyId",
    accessKeyId: "fakeSecretAccessKey",
});

Happy coding!