简体   繁体   中英

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.

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
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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM