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.
$ npm install serverless-plugin-dynamodb --save-devor using yarn
$ yarn add serverless-plugin-dynamodbplugins:
- 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: 1To 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 defaultBy 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: trueTable 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"]- Create tables
- Automatic create IAM Role
- Support TTL attributes
- Support Secondaries Index
- Support Global Secondaries Index
- Support triggers