Lab 5 - DynamoDB streams

When pasting a URL into Twitter, Slack or similar we immediately see a preview. Let’s assume we want to save preview information for every URL we shorten. For each newly created short URL fetch a preview of the website and store it.

Enable DynamoDB streams

DynamoDB supports listening to events via streams. To make use of this we must enable streaming on our table. Various StreamViewTypes exist. We only care about new data being written here:

resources:
  Resources:
    DynamoDBTable:
      Type: AWS::DynamoDB::Table
      Properties:
        StreamSpecification: # Add this to your existing table
          StreamViewType: NEW_IMAGE

Change the event type of your function

To listen to events from DynamoDB you must change the event type. This will subscribe the Lambda function to the DynamoDB stream.

functions:
  unfurl:
    handler: handler.unfurl
    events:
      - stream:
          type: dynamodb
          arn:
            Fn::GetAtt:
            - DynamoDBTable
            - StreamArn