4

我从 SAM 模板创建了一个 lambda 函数,并定义了多个触发器,但在 cloudformation 中只创建了其中一个触发器。这是我的山姆模板:

Myfunc:
    Type: AWS::Serverless::Function
    Properties:
        FunctionName: name
        CodeUri: /
        Handler: app.lambdaHandler
        Runtime: nodejs12.x
        Role: myrole            
        Events:
            Trigger:
                Type: CloudWatchEvent
                Properties:
                    EventBusName: mybus
                    Pattern:
                        source: 
                            - a
                        detail-type:
                            - b
            Trigger:
                Type: CloudWatchEvent
                Properties:
                    EventBusName: mybus
                    Pattern:
                        source:
                            - c

此模板正确部署但仅创建一个规则,并且在 aws 控制台中,它显示在 sam 模板上:

Events:
    Trigger:
      Type: CloudWatchEvent
      Properties:
        EventBusName: mybus
        Pattern:
          source:
          - c

知道如何在 sam 模板中为 lambda 定义多个触发器吗?这是不可能的吗?

4

1 回答 1

5

Events 字段是一个字典,因此您必须为触发器提供不同的名称,如下所示:

Events:
    Trigger:
        Type: CloudWatchEvent
        Properties:
            EventBusName: mybus
            Pattern:
                source: 
                    - a
                detail-type:
                    - b
    TriggerForSourceC:
        Type: CloudWatchEvent
        Properties:
            EventBusName: mybus
            Pattern:
                source:
                    - c
于 2020-02-25T16:37:56.180 回答