首页 > 解决方案 > API 网关与 Lambda 代理集成的 API 文档

问题描述

我定义了一个 SAM 应用程序,在 API 网关后面只有几个 Lambda”

  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: !Ref EnvType
      Auth:
        DefaultAuthorizer: LambdaTokenAuthorizer
        Authorizers:
          LambdaTokenAuthorizer:
            FunctionArn: !GetAtt AuthorizerLambda.Arn
  MyFunction:
    Type: 'AWS::Serverless::Function'
...
      Events:
        MyEvent:
          Type: Api
          Properties:
            RestApiId: !Ref MyApi
            Path: "/MyResource/{proxy+}"
            Method: post

显然,API Gateway 对代理资源了解不多,例如:

从 API Gateway 阶段生成的文档反映了这一点:

swagger: "2.0"
info:
  version: "1.0"
  title: "xxx-dev"
host: "xxx.execute-api.us-west-2.amazonaws.com"
basePath: "/dev"
schemes:
- "https"
paths:
  /MyResource/{proxy+}:
    post:
      responses: {}
      security:
      - LambdaTokenAuthorizer: []
securityDefinitions:
  LambdaTokenAuthorizer:
    type: "apiKey"
    name: "Authorization"
    in: "header"
    x-amazon-apigateway-authtype: "custom"

有没有办法为 API Gateway 提供缺失的位(代理路径、响应模型、请求模型)?最终我需要一个足够好的文档来生成客户端代码/允许一些集成测试。类似的问题在这里-> Aws lambda proxy Swagger template integration

标签: amazon-web-servicesswaggeraws-api-gatewayopenapisam

解决方案


推荐阅读