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 Respuesta
1
Respuesta aceptada

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
EXPERTO
respondido hace 9 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas