检查API Gateway的路由设置,确保较特定的路由被放在更通用的路由之前。
例如,在API Gateway中有两个路由规则,一个是“/books”和另一个是“/books/{isbn}”。如果请求的URL是“/books/123”,API Gateway应该匹配较特定的路由“/books/{isbn}”,而不是更通用的路由“/books”。
以下是一个使用API Gateway的Lambda代理集成的示例代码。它展示了如何在API Gateway中设置路由优先级:
{
"swagger": "2.0",
"info": {
"title": "My Book API",
"version": "1.0"
},
"paths": {
"/books": {
"get": {
"responses": {
"200": {
"description": "Returns a list of all books"
}
},
"x-amazon-apigateway-integration": {
"httpMethod": "GET",
"type": "aws_proxy",
"uri": "arn:aws:lambda:REGION:ACCOUNT_ID:function:FUNCTION_NAME"
}
}
},
"/books/{isbn}": {
"get": {
"responses": {
"200": {
"description": "Returns a book by ISBN"
}
},
"x-amazon-apigateway-integration": {
"httpMethod": "GET",
"type": "aws_proxy",
"uri": "arn:aws:lambda:REGION:ACCOUNT_ID:function:FUNCTION_NAME"
}
}
}
}
}