Home

Awesome

Description

DynamoDB local Streams for serverless-aws-lambda

Installation

yarn add -D serverless-aws-lambda-ddb-streams
# or
npm install -D serverless-aws-lambda-ddb-streams

Usage

use serverless-aws-lambda's defineConfig to import this plugin

// config.js
import { defineConfig } from "serverless-aws-lambda/defineConfig";
import { dynamoStream } from "serverless-aws-lambda-ddb-streams";

export default defineConfig({
  plugins: [dynamoStream(dynamoDbClientConfig, pluginOptions)],
});

DynamoDB Client Config

Configuration used to connect to DynamoDB Tables. By default the plugin uses following configuration:

{
  "endpoint": "http://127.0.0.1:8000",
  "region": "ddblocal",
  "credentials": { "accessKeyId": "test", "secretAccessKey": "test" }
}

If after connecting to the table, StreamEnabled is false, the plugin will try to enable it.

See docker-compose.yml to bootstrap local instance of DynamoDB using Docker.

Plugin Options

Event Source Mapping

# serverless.yml
service: sls-project

frameworkVersion: "3"

plugins:
  - serverless-aws-lambda

custom:
  serverless-aws-lambda:
    configPath: ./config.default

provider:
  name: aws
  runtime: nodejs20.x
  region: eu-west-1

functions:
  myAwsomeLambda:
    handler: src/handlers/lambda.default
    events:
      - stream:
          arn: arn:aws:dynamodb:region:XXXXXX:table/Banana/stream/1970-01-01T00:00:00.000
          batchSize: 3

Supported stream declarations

- stream:
    arn: arn:aws:dynamodb:region:XXXXXX:table/Banana/stream/1970-01-01T00:00:00.000
- stream:
    type: dynamodb
    arn:
      Fn::GetAtt: [MyDynamoDbTable, StreamArn]
- stream:
    arn:
      Fn::ImportValue: MyExportedDynamoDbStreamArnId
- stream:
    arn:
      Ref: MyDynamoDbTableStreamArn
- stream:
    type: dynamodb
    arn: !GetAtt dynamoTable.StreamArn
functions:
  myAwsomeLambda:
    handler: src/handlers/lambda.default
    events:
      - stream:
          arn: arn:aws:dynamodb:region:XXXXXX:table/Banana/stream/1970-01-01T00:00:00.000
          batchSize: 3
          filterPatterns:
            - eventName: [INSERT]
            - dynamodb:
                NewImage:
                  OrderId:
                    N:
                      - numeric: [">", 4]

Supported configurations

✅ supported
🌕 planned
❌ not planned