99x / 99x/serverless-dynamodb-local
Configure DynamoDB stream locally
- Dominant language
- JavaScript
- Stars
- 621
- Forks
- 232
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to trigger a lambda to update an Elastic Search instance whenever changes are made to DynamoDB. I have the stream set up in my `serverless.yaml` file, and when I deploy it, the lambda is triggered. However, when I run this with `serverless-offline`, the function is not triggered.
Here is my `serverless.yaml`
```
service: my-service
plugins:
- serverless-dynamodb-local
- serverless-offline
custom:
tableName: "dynamodb-${self:provider.stage}"
dynamodb:
start:
migrate: true
provider:
name: aws
runtime: nodejs6.10
stage: dev
region: ca-central-1
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:DescribeStream
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:ListStreams
Resource:
- { "Fn::GetAtt": ["DynamoDbTable", "Arn" ] }
functions:
# Request that should trigger function
add:
handler: handler.add
events:
- http:
path: api/add
method: POST
# Function that should be triggered
updateIndices:
handler: handler.updateIndices
events:
- stream:
type: dynamodb
arn:
Fn::GetAtt:
- DynamoDbTable
- StreamArn
startingPosition: LATEST
batchSize: 1
enabled: true
resources:
Resources:
DynamoDbTable:
Type: "AWS::DynamoDB::Table"
DeletionPolicy: Delete
Properties:
TableName: ${self:custom.tableName}
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
ElasticSearchInstance:
Type: "AWS::Elasticsearch::Domain"
Properties:
EBSOptions:
EBSEnabled: true
VolumeType: gp2
VolumeSize: 10
ElasticsearchClusterConfig:
InstanceType: t2.small.elasticsearch
InstanceCount: 1
DedicatedMasterEnabled: false
ZoneAwarenessEnabled: false
ElasticsearchVersion: "6.0"
```
Is what I'm trying to do possible with `serverless-dynamodb-local`? Or is there more configuration that needs to be added to fire this function locally?
Thanks for the help!
Contributor guide
Research direction
Start with the serverless.yaml configuration and the serverless-dynamodb-local and serverless-offline plugins. Trace the add handler's DynamoDB write and the updateIndices stream handler, then determine whether local changes reach the stream trigger. Done means the documented local setup causes updateIndices to run after the add function changes DynamoDB.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, javascript, node.js
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100