Cloudformation DynamoDB on new Record add to SQS then Trigger lambda function fromSQS

0

Hello Please i need help with cloud formation i have a dynamoDB (studentVisit) with attribute

studentVisit
timestamp (Primary Key)
id (Secondary Key)
Parent Phone

i want on every New Record(Inserted) to insert into an SQS studentNotificationQue and that Que should tigger a lambda function Please inned help on this with sample cloudformation code setup

Thank you.

1 Answer
1
Accepted Answer

Hi.

What you can do is to utilize DynamoDB streams and EventBridge. DynamoDB Stream -> EventBridge Pipes -> EventBridge Bus -> SQS -> Lambda

Template would look like this, not all part present

  DynamoDBTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: myTable
      BillingMode: PAY_PER_REQUEST
      StreamSpecification:
        StreamViewType: NEW_IMAGE
      .......

  # Event Bus (Target)
  MyBus:
    Type: AWS::Events::EventBus
    Properties:
      Name: myBus

  # EventBridge Pipe
  Pipe:
    Type: AWS::Pipes::Pipe
    Properties:
      Name: DynamoDB-to-eventbridge
      Description: Pipe to connect DeviceInventoryTable Stream to EventBridge event bus
      RoleArn: !GetAtt EventBridgePipeRole.Arn
      Source: !Ref DynamoDBTableStreamArn
      SourceParameters:
        DynamoDBStreamParameters:
          StartingPosition: LATEST
          BatchSize: 1
      Target: !GetAtt MyBus.Arn
      TargetParameters:
        EventBridgeEventBusParameters:
          DetailType: MyDetailType
          Source: MyApp

You then create an SQS queue and a Lambda function where the SQS queue is the target for EventBridge Rule.

You can check my blog post Building a Multi-region Serverless IoT system on community.aws in this post I use this technique to replicate IoT Devices cross-region.

Hope it helps!

profile picture
EXPERT
answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions