Search code examples
amazon-web-servicesamazon-dynamodbamazon-dynamodb-streams

DynamoDB doesn't show updated item data in stream


I have a DynamoDB table with a stream of type: NEW_IMAGE, but i only get new added items to the db in the stream. I don't get the data of when an existing item was modified. Is there a way to do this in streams? To send the data of the updated existing items in a stream as well as new items?

Below is my Serverless code

OrdersTable:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: OrdersTable-${self:provider.stage}
    BillingMode: PAY_PER_REQUEST
    AttributeDefinitions:
      - AttributeName: id
        AttributeType: S
      - AttributeName: createdAt
        AttributeType: S
      - AttributeName: ticker 
        AttributeType: S
      - AttributeName: orderRate 
        AttributeType: S  
    KeySchema:
      - AttributeName: id
        KeyType: HASH
      - AttributeName: createdAt
        KeyType: RANGE        
    GlobalSecondaryIndexes:
      - IndexName: ticker_orderRate
        KeySchema:
          - AttributeName: ticker
            KeyType: HASH
          - AttributeName: orderRate
            KeyType: RANGE
        Projection:
          ProjectionType: ALL      
    StreamSpecification:
      StreamViewType: NEW_IMAGE    

Solution

  • Updates should be part of the stream as well, NEW_IMAGE just means that only the changed version will be sent to the stream, i.e. the "after" version of the item.

    NEW_IMAGE - The entire item, as it appears after it was modified, is written to the stream.

    Docs

    Note that items need to be changed for them to appear in the stream, an UpdateItem call that doesn't result in a change to the data won't show up.