Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference external aws resource with default in serverless framework?

I want to reference an external aws resource in serverless framework. However, if it does not exist, I want to fall back to a default value

For example:

functions:
  create:
    handler: posts.create
    events:
      - http:
          path: posts/create
          method: post
          authorizer: arn: xxx:xxx:Lambda-Name

For authorizer, I want to reference a function if it exists, and if it does not exist, to default to another value


1 Answers

If your authorizer function is part of another cloud formation stack, you can use CloudFormation outputs to do this. If not, there are still several other variable solutions in the docs.

To do that conditionally, you'd combine it with a default. For example:

 ${cf:my-stack-${self:custom.stage}.AuthorizerArn, 'some-default-arn'}
like image 57
Aaron Stuyvenberg Avatar answered Apr 02 '26 16:04

Aaron Stuyvenberg