Skip to content

Add support for running DynamoDB within docker #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ serverless-dynamodb-local

## This Plugin Requires
* serverless@^1
* Java Runtime Engine (JRE) version 6.x or newer
* Java Runtime Engine (JRE) version 6.x or newer _OR_ docker CLI client

## Features
* Install DynamoDB Local
* Install DynamoDB Local Java program
* Run DynamoDB Local as Java program on the local host or in docker container
* Start DynamoDB Local with all the parameters supported (e.g port, inMemory, sharedDb)
* Table Creation for DynamoDB Local

Expand All @@ -24,7 +25,7 @@ plugins:
```

## Using the Plugin
1) Install DynamoDB Local
1) Install DynamoDB Local (unless using docker setup, see below)
`sls dynamodb install`

2) Add DynamoDB Resource definitions to your Serverless configuration, as defined here: https://serverless.com/framework/docs/providers/aws/guide/resources/#configuration
Expand All @@ -36,11 +37,16 @@ plugins:
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.

## Install: sls dynamodb install
This installs the Java program locally. If using docker, this step is not required.

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.

## Start: sls dynamodb start
This starts the DynamoDB Local instance, either as a local Java program or, if the `--docker` flag is set,
by running it within a docker container. The default is to run it as a local Java program.

All CLI options are optional:

```
Expand All @@ -57,6 +63,8 @@ All CLI options are optional:
--migrate -m After starting DynamoDB local, create DynamoDB tables from the Serverless configuration.
--seed -s After starting and migrating dynamodb local, injects seed data into your tables. The --seed option determines which data categories to onload.
--convertEmptyValues -e Set to true if you would like the document client to convert empty values (0-length strings, binary buffers, and sets) to be converted to NULL types when persisting to DynamoDB.
--docker Run DynamoDB inside docker container instead of as a local Java program
--dockerImage Specify custom docker image. Default: amazon/dynamodb-local
```

All the above options can be added to serverless.yml to set default configuration: e.g.
Expand All @@ -79,6 +87,24 @@ custom:
# noStart: true
```

Docker setup:
```yml
custom:
dynamodb:
# If you only want to use DynamoDB Local in some stages, declare them here
stages:
- dev
start:
docker: true
port: 8000
inMemory: true
migrate: true
seed: true
convertEmptyValues: true
# Uncomment only if you already have a DynamoDB running locally
# noStart: true
```

## Migrations: sls dynamodb migrate
### Configuration
In `serverless.yml` add following to execute all the migration upon DynamoDB Local Start
Expand Down