Search code examples
amazon-web-servicesserverless-frameworkserverless

How to specify multiple resources in a single entry in serverless.yml?


I would like to be able to specify multiple resources using a single entry in serverless.yml.

My use case is as follows:

reportFatalError:
    handler: "handler.reportFatalError"
    events:
    - cloudwatchLog:
        # "*" implies wish to insert wildcard
        logGroup: "/aws/lambda/*-${opt:stage}-*"
        filter: "\"FATAL\""

Naturally, I would like the Fatal Error Reporter to report the Fatal Error from any logGroup, and explicitly specifying all of them is a recipe for poorly maintained serverless.yml in the future.

Is there some way to specify a wildcard or loop over the logGroups as serverless deploys?


Solution

  • Unfortunately there isn't a way to do this with wildcards. This is a limitation of AWS, not Serverless.

    You could write a script that loaded a list of all your CloudWatch logGroups and then applied those events to your reportFatalError function on deployment.

    See here: https://serverless.com/framework/docs/providers/aws/guide/variables/#reference-variables-in-javascript-files