【问题标题】:How to get reference to aws api gateway in serverless framework如何在无服务器框架中获取对 aws api 网关的引用
【发布时间】:2022-06-16 21:38:42
【问题描述】:
provider:
  name: aws
  runtime: nodejs14.x

functions:
  hello:
    handler: handler.hello
    events:
      - httpApi:
          path: /
          method: get
          RestApiId:
            Ref: TestApi // How to get reference of AWS::Serverless::Api i.e. TestApi here

resources:
  Resources:
    authFunction:
      Type: AWS::Serverless::Function
      Properties:
        CodeUri: .
        Handler: handler.hello

    TestApi:
      DependsOn: AuthFunction
      Type: AWS::Serverless::Api
      Properties:
        StageName: dev
        Auth:
            DefaultAuthorizer: LambdaRequestAuthorizer
            Authorizers:
              LambdaRequestAuthorizer:
                FunctionPayloadType: REQUEST
                FunctionArn: !GetAtt AuthFunction.Arn

得到错误:

Configuration error at 'functions.hello': unrecognized property 'RestApiId'

【问题讨论】:

    标签: amazon-web-services serverless-framework aws-serverless


    【解决方案1】:

    让我们首先澄清一些事情。

    httpApi 事件使用的是 HTTP API,而不是来自 AWS Api Gateway 的 REST API。

    您可以通过以下方式指定外部创建的 HTTP API:

    provider:
      httpApi:
        id: <your http api reference>
    

    如果您想使用 REST API,则需要使用 http 事件类型并将其设置为:

    provider:
      apiGateway:
        restApiId: <your rest api reference>
    

    【讨论】:

      猜你喜欢
      • 2019-04-16
      • 2018-08-27
      • 2019-10-07
      • 1970-01-01
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 2017-12-18
      • 2021-05-06
      相关资源
      最近更新 更多