我有3个API:
所有这3个API都必须位于同一API网关下。对于前两个API,我已将我的SAM模板配置如下:
JWTCreateUser:
Type: AWS::Serverless::Function
Properties:
CodeUri: create-user-jwt-lambda/target/JWTCreateUser-1.0-SNAPSHOT.jar
Handler: com.company.CreateUserHandler::handleRequest
Runtime: java8
Events:
CreateUser:
Type: Api
Properties:
RestApiId:
Ref: OrderingAPI
Path: /company/api1
Method: post
GenerateJWTToken:
Type: AWS::Serverless::Function
Properties:
CodeUri: login-jwt-lambda/target/JWTGenerateToken-1.0-SNAPSHOT.jar
Handler: com.company.GenerateJWTFunctionHandler::handleRequest
Runtime: java8
Events:
LoginUser:
Type: Api
Properties:
RestApiId:
Ref: OrderingAPI
Path: /company/api2
Method: post
Auth:
Authorizer: LoginAuthorizer
对于第三个API,我在SAM模板中添加了以下内容:
OrderingAPI:
Type: AWS::Serverless::Api
Properties:
StageName: v1
DefinitionBody:
swagger: "2.0"
info:
title: "Ordering APIs"
paths:
/company/api3:
post:
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- name: "Content-Type"
in: "header"
required: false
type: "string"
responses:
"200":
description: "200 response"
"201":
description: "201 response"
x-amazon-apigateway-request-validator: "Validate body"
x-amazon-apigateway-integration:
uri: "https://mycompany.com/order"
responses:
default:
statusCode: "200"
responseTemplates:
application/json: "#set($allParams = $input.params())\n$input.json('$')"
requestParameters:
integration.request.header.Ticket: "method.request.header.Ticket"
integration.request.header.ticket: "method.request.header.ticket"
integration.request.header.Content-Type: "method.request.header.Content-Type"
integration.request.header.tenant: "method.request.header.tenant"
passthroughBehavior: "when_no_match"
httpMethod: "POST"
type: "http"
这里的问题是-仅创建了一个API(/ company / api3),其余2个API均未创建。这是因为我为/ company / api3声明了一个摇摇欲坠,该选项被/ company / api1和/ company / api2覆盖了自动生成的摇摇欲坠。
有没有一种方法可以创建 AWS :: Serverless :: Api 而无需指定swagger(DocumentBody),但是我们可以配置HTTP端点(在我的情况下为/ company / api3)?这可能会有帮助。