SQS 使用 CloudFormation 触发 AWS Lambda 函数

问题描述 投票:0回答:2

我需要在某些进程将消息推送到 Amazon SQS 时触发 AWS Lambda 函数。我有以下 CloudFormation 配置。另一个进程能够将消息推送到 SQS,但它没有触发 Lambda 函数

任何帮助将不胜感激!

TestFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: abc/xxx/
      Handler: com.test.TestHandler::handleRequest
      Runtime: java11
      MemorySize: 512
      Timeout: 120
      FunctionName: !Join [ "-", [ !Ref TestPrefix, "TestFunction" ] ]
      Role: !Ref LambdaIAMRole
      VpcConfig:
        SecurityGroupIds:
          - !Ref TestSecurityGroupId
        SubnetIds: !Ref TestSubnetIds
      Events:
        MySQSEvent:
          Type: SQS
          Properties:
            Queue: !GetAtt TestQueue.Arn
            BatchSize: 1


TestQueue:
  Type: AWS::SQS::Queue
  Properties:
    QueueName: !Ref TestQueueName
    Enabled: true
    MessageRetentionPeriod: 300
    VisibilityTimeout: 900
amazon-web-services aws-lambda amazon-sqs aws-event-bridge
2个回答
1
投票

您可以使用 EventBridge Pipes 执行此操作。它对我有用!

EventBridge Pipes 在 Reinvent 2022 中宣布

EventBridge Pipes 提供了一种更简单、一致且经济高效的方法来创建事件生产者和消费者之间的点对点集成,从而将 EventBridge 产品扩展到事件总线和调度之外。

源将是 SQS,目标将是 Lambda。

早些时候,如果没有 Eventbridge 管道,这是不可能的,但现在可以了。您可以查看 eventbridge 管道的各种 sourcestarget

只需将其扩展到您的 CFn 模板:Cloudformation EventBridge 文档.


0
投票

您不能直接从 SQS 触发 lambda 函数。您需要创建一个Event Source Mapping.

© www.soinside.com 2019 - 2024. All rights reserved.