如何在无服务器框架中默认引用外部aws资源?

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

我想在无服务器框架中引用外部 aws 资源。但是,如果它不存在,我想回退到默认值

例如:

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

对于authorizer,我想引用一个函数,如果存在,如果不存在,则默认为另一个值

如果您的授权函数是另一个云形成堆栈的一部分,您可以使用 CloudFormation outputs to do this. If not, there are still several other variable solutions in the docs

要有条件地执行此操作,您需要将其与默认值结合使用。例如:

 ${cf:my-stack-${self:custom.stage}.AuthorizerArn, 'some-default-arn'}