Home

Awesome

serverless npm version License: MIT

serverless-dynamodb-fixtures

Serverless plugin to load data on DynamoDB tables.

This Plugin Requires

Usage

You can use this plugin in two ways:

See the configuration flag enable, for each fixture block, for more information.

Configuration

You should include the plugin as dev dependency, and in your serverless.yml file. Then, as a custom variable, you should include a fixtures variable with the configuration of the plugin. The fixtures configuration should contain a rules element. and optionally an endpoint element if you want to use a local instance of DynamoDB (remember to set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables if you use dynamodb local).

The accepted rules configuration is an array of fixtures, where each fixture has the following variables:

Important: sources or rawsources must be defined (at least one of them).

Examples

Serverless configuration

plugins:
  - serverless-dynamodb-fixtures

custom:
  fixtures:
    endpoint: http://localhost:8000
    rules:
        - table: TABLE1-${self:custom.stage}
        [enable: true]
        sources:
            - ./file1-${self:custom.stage}.yml
            - ./file2-${self:custom.stage}.json
        rawsources:
            - ./rawFormatFile1-${self:custom.stage}.yml

        - table: TABLE2-${self:custom.stage}
        [stage: test]
        [concurrentWrites: 5]
        sources:
            - ./file3-${self:custom.stage}.yml

Autogeneration of id

serverless.yml

plugins:
  - serverless-dynamodb-fixtures

custom:
  fixtures:
    - table: TABLE1-${self:custom.stage}
      autogeneratedId: id
      sources:
        - ./file.yml

file.yml

- name: Jack London
- name: John Doe

It will be loaded in DynamoDB as follow:

- id: 45745c60-7b1a-11e8-9c9c-2d42b21b1a3e
  name: Jack London
- id:  35625c60-8b1f-22e9-1c3c-1ae1c16a2f4e
  name: John Doe

Fixtures

Source in yml format

- id: 1
  name: Jack London
- id: 2
  name: John Doe

Source in json format

[
    {"id":1, "name":"Jack London"},
    {"id":2, "name":"John Doe"}
]

Thanks