Skip to content

daaru00/serverless-plugin-dynamodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serverless DynamoDB

npm

A serverless plugin to easily create DynamoDB tables from configurations files. This plugin will also edit the Lambda Role to allow any operations on created tables.

Usage

Installation

$ npm install serverless-plugin-dynamodb --save-dev

or using yarn

$ yarn add serverless-plugin-dynamodb

Configuration

plugins:
  - serverless-plugin-dynamodb

custom:
  tables:
    todo:
      name: ${self:service}-${self:provider.stage}-ToDo # Table Name
      primaryKey: # Primary Key configurations,  default type: S
        name: id
        type: 'S'
      rangeKey: # Range Key configurations, optional, default type: S
        name: date
        type: 'S'
      throughput: # ProvisionedThroughput configuration, default: read 1 and write 1
        read: 1
        write: 1

TTL

To add an TimeToLive specification on table resource set the ttl table configuration:

custom:
  tables:
    todo:
      name: ${self:service}-${self:provider.stage}-ToDo
      primaryKey:
        name: id
        type: 'S'
      ttl: 
        attribute: ttl
        enabled: true # Optional, true by default

Policy

By default the plugin edit the common lambda function policy to allow any function to do any data operations

{
  "Effect": "Allow",
  "Action": [
    "dynamodb:*"
  ],
  "Resource": "<table resource>"
}

to disable this behaviour set the config skipTablePolicy to true

custom:
  skipTablePolicy: true

Resource names

Table resource will be create using the table configuratin key name in camel case prepending "Table" before the name, for example:

custom:
  tables:
    todo:
      name: ${self:service}-${self:provider.stage}-ToDo
      primaryKey:
        name: id
        type: 'S'

will create a AWS::DynamoDB::Table resource with key name TableTodo, so you can reference it in this way:

iamRoleStatements:
  - Effect: Allow
    Action:
      - dynamodb:PutItem
    Resource: 
      - "Fn::GetAtt": ["TableTodo", "Arn"]

TODO

  • Create tables
  • Automatic create IAM Role
  • Support TTL attributes
  • Support Secondaries Index
  • Support Global Secondaries Index
  • Support triggers

About

Serverless plugin to easily create DynamoDB tables

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published