5

I created a lambda function from a SAM template, and defined multiple triggers, but only one of these triggers is being created in cloudformation. This is my sam template:

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

This template deploys correctly but creates only one rule, and in the aws console, on the sam template it shows:

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

Any idea how to define multiple triggers for a lambda in the sam template? Is it impossible?

1 Answer 1

7

The Events fields is a dictionary, so you have to give different names to your triggers as in:

Events:
    Trigger:
        Type: CloudWatchEvent
        Properties:
            EventBusName: mybus
            Pattern:
                source: 
                    - a
                detail-type:
                    - b
    TriggerForSourceC:
        Type: CloudWatchEvent
        Properties:
            EventBusName: mybus
            Pattern:
                source:
                    - c
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.