Reputation: 173
I have searched high and low and can not for the life of me get serverless to setup a dynamodb trigger.
I have used:
- stream:
type: dynamodb
batchSize: 100
enabled: true
arn:
Fn::GetAtt:
- MyDynamoDbTable
- StreamArn
I tried a hard coded arn and nothing has occurred that I can see in the aws console. I am new to serverless. If you have any pointers please post.
Upvotes: 12
Views: 11322
Reputation: 1959
We had the same problem. And the answer was basically that you couldn't. Or more precisely, you couldn't without having to destroy the Dynamo DB table every time. We built this plugin that allows you to connect it up. https://www.npmjs.com/package/serverless-dynamo-stream-plugin.
Our team creates Dynamo DB tables via ansible or terraform depending on the project, and then we use this plugin to wire it together.
We are maintaining this via our open source repo on github, so if you have any issues or suggestions, you can message me here or there. Hope this helps, as we are using it in our production code base now.
Upvotes: 2
Reputation: 501
Example on how to configure dynamodb stream in serverless.yml
functions:
dynamodb-trigger:
handler: yourfunction.handler
events:
- stream:
type: dynamodb
batchSize: 1
startingPosition: LATEST
arn:
Fn::GetAtt:
- MyDynamoDbTable
- StreamArn
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:ListStreams
- dynamodb:DescribeTable
- dynamodb:UpdateItem
- dynamodb:GetItem
Resource:
- "Fn::Join": ["", ["arn:aws:dynamodb:" , {"Ref": "AWS::Region"}, ":", {"Ref": "AWS::AccountId"} , ":table/${self:provider.environment.MFA_DYNAMODB_TABLE}"] ]
resources:
Resources:
MyDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Delete
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:provider.environment.MFA_DYNAMODB_TABLE}
StreamSpecification:
StreamViewType: NEW_IMAGE
Upvotes: 25
Reputation: 173
events:
- stream: arn:aws:dynamodb:us-west-2:xxxxxx:table/tableName/stream/2018-04-19T16:40:37.833
this is proper way to get the trigger to be created on dynamodb
Upvotes: 5