【问题标题】:AWS::S3::Bucket LambdaConfiguration in multiple AWS Lambdas多个 AWS Lambda 中的 AWS::S3::Bucket LambdaConfiguration
【发布时间】:2021-06-13 03:28:58
【问题描述】:

我有 4 个 AWS Lambda 在创建某些文件时应该读取 S3 存储桶(S3 事件),但在 cloudformation 中我只能使用 1 个 lambda ARN,请参阅内部 AWS::S3::Bucket LambdaConfiguration

如何在 Bucket Lambda Configuration 中触发多个 Lambda?

【问题讨论】:

    标签: amazon-web-services amazon-s3 aws-lambda amazon-cloudformation


    【解决方案1】:

    S3 不提供这种开箱即用的扇出,而只能通过例如社交网络。
    您需要将通知推送到 SNS 主题而不是 lambda,然后

    • 为该主题订阅四个 lambda 或
    • 为主题订阅四个队列,并让每个 lambda “订阅”一个队列

    【讨论】:

      【解决方案2】:

      AWS 最近宣布了S3 Event Notifications with Amazon EventBridge。因此,您可以在存储桶上启用 EventBridge 通知,然后让这些事件触发一个(或多个)Lambda 函数。

      使用 AWS SAM 的示例实施:

      AWSTemplateFormatVersion : '2010-09-09'
      Transform: AWS::Serverless-2016-10-31
      Description: 'S3 EventBridge Example'
      
      Parameters:
        BucketName:
          Type: String
          Description: 'Name of the bucket to be created'
      
      Resources:
      
        S3Bucket:
          Type: AWS::S3::Bucket
          Properties:
            BucketName: !Ref BucketName
            NotificationConfiguration:
              EventBridgeConfiguration:
                EventBridgeEnabled: true
      
        S3EventProcessor:
          Type: AWS::Serverless::Function
          Properties:
            FunctionName: S3EventListener
            Architectures:
              - arm64
            Runtime: nodejs14.x
            Handler: index.handler
            InlineCode: |
              exports.handler = (event, context) => {
                console.log('event:', JSON.stringify(event));
              }
            Events:
              S3EventBridgeRule:
                Type: EventBridgeRule
                Properties:
                  Pattern:
                    source:
                      - aws.s3
                    detail:
                      bucket:
                        name:
                          - !Ref BucketName
      

      【讨论】:

      • 感谢您的回答
      【解决方案3】:

      我认为Step functions 正是您想要的。 S3-related tutorial 也很有用

      【讨论】:

        猜你喜欢
        • 2022-12-26
        • 1970-01-01
        • 2023-02-24
        • 2022-01-26
        • 1970-01-01
        • 1970-01-01
        • 2019-01-11
        • 2021-01-27
        • 2018-07-12
        相关资源
        最近更新 更多