• Stars
    star
    624
  • Rank 71,995 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Serverless Dynamodb Local Plugin - Allows to run dynamodb locally for serverless

serverless-dynamodb-local

Join the chat at https://gitter.im/99xt/serverless-dynamodb-local npm version License: MIT

This Plugin Requires

  • serverless@^1
  • Java Runtime Engine (JRE) version 6.x or newer OR docker CLI client

Features

  • 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

Install Plugin

npm install --save serverless-dynamodb-local

Then in serverless.yml add following entry to the plugins array: serverless-dynamodb-local

plugins:
  - serverless-dynamodb-local

Using the Plugin

  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

  3. Start DynamoDB Local and migrate (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 --migrate

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:

--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.
--heapInitial                 The initial heap size
--heapMax                     The maximum heap size
--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.

custom:
  dynamodb:
  # If you only want to use DynamoDB Local in some stages, declare them here
    stages:
      - dev
    start:
      port: 8000
      inMemory: true
      heapInitial: 200m
      heapMax: 1g
      migrate: true
      seed: true
      convertEmptyValues: true
    # Uncomment only if you already have a DynamoDB running locally
    # noStart: true

Docker setup:

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

custom:
  dynamodb:
    start:
      migrate: true

AWS::DynamoDB::Table Resource Template for serverless.yml

resources:
  Resources:
    usersTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: usersTable
        AttributeDefinitions:
          - AttributeName: email
            AttributeType: S
        KeySchema:
          - AttributeName: email
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1

Note: DynamoDB local doesn't support TTL specification, therefore plugin will simply ignore ttl configuration from Cloudformation template.

Seeding: sls dynamodb seed

Configuration

In serverless.yml seeding categories are defined under dynamodb.seed.

If dynamodb.start.seed is true, then seeding is performed after table migrations.

If you wish to use raw AWS AttributeValues to specify your seed data instead of Javascript types then simply change the variable of any such json files from sources: to rawsources:.

custom:
  dynamodb:
    start:
      seed: true

    seed:
      domain:
        sources:
          - table: domain-widgets
            sources: [./domainWidgets.json]
          - table: domain-fidgets
            sources: [./domainFidgets.json]
      test:
        sources:
          - table: users
            rawsources: [./fake-test-users.json]
          - table: subscriptions
            sources: [./fake-test-subscriptions.json]
> sls dynamodb seed --seed=domain,test
> sls dynamodb start --seed=domain,test

If seed config is set to true, your configuration will be seeded automatically on startup. You can also put the seed to false to prevent initial seeding to use manual seeding via cli.

[
  {
    "id": "John",
    "name": "Doe",
  },
]

Using DynamoDB Local in your code

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',
    accessKeyId: 'DEFAULT_ACCESS_KEY',  // needed if you don't have aws credentials at all in env
    secretAccessKey: 'DEFAULT_SECRET' // needed if you don't have aws credentials at all in env
})

e.g. for dynamodb document client sdk

new AWS.DynamoDB({
    region: 'localhost',
    endpoint: 'http://localhost:8000',
    accessKeyId: 'DEFAULT_ACCESS_KEY',  // needed if you don't have aws credentials at all in env
    secretAccessKey: 'DEFAULT_SECRET' // needed if you don't have aws credentials at all in env

})

Using with serverless-offline plugin

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.

The serverless dynamodb start command can be triggered automatically when using serverless-offline plugin. Please note that you still need to install DynamoDB Local first.

Add both plugins to your serverless.yml file:

plugins:
  - serverless-dynamodb-local
  - serverless-offline

Make sure that serverless-dynamodb-local is above serverless-offline so it will be loaded earlier.

Now your local DynamoDB database will be automatically started before running serverless offline.

Using with serverless-offline and serverless-webpack plugin

Run serverless offline start. In comparison with serverless offline, the start command will fire an init and a end lifecycle hook which is needed for serverless-offline and serverless-dynamodb-local to switch off both ressources.

Add plugins to your serverless.yml file:

plugins:
  - serverless-webpack
  - serverless-dynamodb-local
  - serverless-offline #serverless-offline needs to be last in the list

Reference Project

Links

License

MIT

More Repositories

1

boilerplatejs

Your own boilerplate code to start your next big javascript project. We incorporate the best design practices with best in market open source libraries.
JavaScript
278
star
2

first-born

Component library for React Native
JavaScript
271
star
3

emojicpp

Emoji πŸ˜„ for c++ developers πŸ‘
C++
267
star
4

serverless-react-boilerplate

A serverless react boilerplate for offline development
JavaScript
260
star
5

timercpp

Javascript like setTimeout and setInterval for c++ developers
C++
246
star
6

serverless-dynamodb-client

Serverless Dynamodb Client to automatically switch between AWS and Local instances
JavaScript
74
star
7

sinhala-express-js

ΰΆ‘ΰΆšΰ·Šΰ·ƒΰ·ŠΰΆ΄ΰ·Šβ€ΰΆ»ΰ·ƒΰ·Š ࢒ේ. ΰΆˆΰ·ƒΰ·Š ΰ·ƒΰ·’ΰΆ±ΰ·Šΰ·„ΰΆ½ ΰΆ΄ΰΆ»ΰ·’ΰ·€ΰΆ»ΰ·ŠΰΆ­ΰΆ±ΰΆΊ
JavaScript
68
star
8

react-scaffolder

⚑ Scaffolding tool for React
JavaScript
44
star
9

dynamodb-localhost

Dynamodb localhost runner for development and testing
JavaScript
35
star
10

serverless-delivery-framework

This is a boilerplate for version release pipeline with serverless framework
JavaScript
31
star
11

steroidslibrary

Framework for simplifying microservices in TypeScript focusing on business logic
TypeScript
27
star
12

runn

Make your own terminal aliases easily!
JavaScript
21
star
13

dynamodb-migrations

Manage DynamoDB table creation and seed templates in your codebase
JavaScript
18
star
14

azure-jwt-verify

Verify jwt token issued from azure active directory b2c service
JavaScript
18
star
15

w3c-link-validator

Command line tool, identifying broken links, validate basic html standards and reporting
JavaScript
18
star
16

github-manager

πŸš€ Manage GitHub repositories with ease
JavaScript
17
star
17

dotitude

A community driven by 99X Technology with the collaboration of Universities and Industry to enlighten the future of undergraduates.
17
star
18

RadiumRest

A Portable Microframework for .NET
C#
16
star
19

CodeSpecJS

UI Automation Testing without writing a single line of code
TypeScript
15
star
20

scikit-recommender-api

Recommender system API service which runs as a simplified web service.
JavaScript
13
star
21

walk2win

Online Walking challenge for workplaces
TypeScript
12
star
22

emojideno

Emoji πŸ˜„ for deno developers πŸ‘
TypeScript
12
star
23

aws-userpool-boilerplate

Getting started with AWS Cognito User Pool
JavaScript
11
star
24

simpletasks.js

Simple time based task queue for js
JavaScript
10
star
25

articles-of-the-week

Awesome articles weekly πŸ“–
10
star
26

jira-journal

🎭 Bot that interacts as your bullet journal for JIRA worklogs.
JavaScript
9
star
27

dynamodb-schema-migrate

Easily Migrate a Existing Schema(Tables) from one Region to another Region
JavaScript
8
star
28

discourse-sdk

Node SDK for discourse forum software
JavaScript
8
star
29

protractor-starter

Protractor end to end testing boilerplate
JavaScript
7
star
30

pdf2-s3

This library will download a pdf from a given web url and upload it to a given s3 bucket.
JavaScript
7
star
31

serverless-dependency-install

Serverless plugin to manage dependencies.
JavaScript
7
star
32

any2pdf.js

This library contains functionality which can help convert documents to PDF using javascript on the browser.
JavaScript
6
star
33

architecture.99x.io

This repository contains the best practices and processes we use for architecture to share with the community
JavaScript
6
star
34

spec-handbook

Curated list of quality standards and opinionated implementation guides for software products
6
star
35

gulp-dependency-install

This gulp plugin provides commands to install npm dependencies in multiple package.json files with a single command. It also allows to define custom local dependencies inside package.json.
JavaScript
6
star
36

dependency-install

Install dependencies in multiple package.json files also allowing to define custom dependency paths
JavaScript
5
star
37

gsoc

All about 99xt GSoC organization
5
star
38

gh-code

Visual Studio code plugin to easily manage issues in a git hub repository
TypeScript
4
star
39

garray

G-array is a GoLang library, that contains the generic function to do the array operations.
Go
4
star
40

ConnectAPIBuddy

An API testing web tool
TypeScript
4
star
41

youtube-queuing-bot

A full screen web app to play youtube playlist videos (will be used for the RPI)
JavaScript
4
star
42

openhack

Official website of OpenHack '19
CSS
4
star
43

react-native-aws-cognito-userpools

Authenticating users using AWS cognito user pools
JavaScript
4
star
44

product-central-architectures

HTML
3
star
45

24sevenoffice-php-adapter

A PHP Adapter to use in integrations with 24sevenoffice.com
PHP
3
star
46

react-boilerplate

Unopinionated boilerplate for react, react-flux or react-redux.
JavaScript
3
star
47

hacktitude-web

Hacktitude website
CSS
3
star
48

covid19-whatsapp

WhatsApp Bot to provide information about the Covid19 Pandemic for Sri Lankan Citizens
Python
3
star
49

dynamodb-data-transform

Manage DynamoDB data transformation in your codebase
JavaScript
3
star
50

articlesoftheweek

Articles of the week website
HTML
3
star
51

owasp-cli

CLI for OWASP free and open software security community API
JavaScript
2
star
52

cla-bot

The bot manages signed contributors of an ORG
TypeScript
2
star
53

CodeSpecJSClient

A Web client for CodeSpecJS
JavaScript
2
star
54

avurudu-game

JavaScript
2
star
55

steroidsboilerplate

JavaScript
2
star
56

seranet.api

C#
2
star
57

hexweb

Official Website
HTML
2
star
58

realtime-toastr

This will give real time non-blocking notifications from server to client
JavaScript
2
star
59

wp-deploy

A WordPress deployment tool
Python
2
star
60

earnshark-sdk-ruby

This is a Ruby SDK to call https://app.earnshark.com API. Contains methods to call the EarnShark API making the application integration fast.
Ruby
2
star
61

promise-utils

TypeScript
2
star
62

callstatus-notifier

This application allows to trigger a IOT device when skype call is in progress
C#
2
star
63

Colombocamps

HTML
2
star
64

trendviewer

visualising sentiments on long term social trends - from social feeds like twitter , FB
XSLT
2
star
65

contributors-shield

Generate an image for the contributors of a repo
JavaScript
2
star
66

optimaxer-web

A lightweight JavaScript utility library designed for running local language models (LLMs) like Gemma 2B directly on edge devices. This project aims to provide developers with easy-to-use tools for integrating AI capabilities into web applications without relying on external servers.
TypeScript
2
star
67

aws-api-gateway-policy-generator

TypeScript
1
star
68

vue-boilerplate

JavaScript
1
star
69

mongodb-backup

Docker container for MongoDB Backups
Shell
1
star
70

udf-ios-boilerplate

Boilerplate IOS Application that uses UDF Architecture
Swift
1
star
71

earnshark-sdk-dot-net

C#
1
star
72

simple-rss-feed-reader

A simple rss feed reader which can be setup in local
1
star
73

social-media-day-2017

The official webpage for Social Media Day 2017 - #MyDreamITJob
CSS
1
star
74

canvasx

Canvas Component for React
TypeScript
1
star
75

symptom-inform

This repository contains a sample application to submit medical symptoms
JavaScript
1
star