Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

serverless dynamodb streams and triggers

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.

like image 252
jta Avatar asked Apr 17 '18 18:04

jta


2 Answers

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
like image 66
mel Avatar answered Jan 24 '23 09:01

mel


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

like image 39
jta Avatar answered Jan 24 '23 11:01

jta