AWS API Gateway:如何将多个方法请求参数合并为一个集成请求参数 [英] AWS API Gateway: How to combine multiple Method Request params into a single Integration Request param
问题描述
我想使用API网关作为S3的代理.该存储区由一个由以下两部分组成的组合键设置键:[userId]-[documentId].
I'd like to use API Gateway as a proxy to S3. The bucket is keyed by a composite key made up of two parts like this: [userId]-[documentId].
UserId作为路径参数进入API网关,documentId作为请求参数进入,例如: [gateway-url]/user1?documentId = doc1
UserId comes to API Gateway as a path parameter, documentId comes in as a request parameter, for example: [gateway-url]/user1?documentId=doc1
如何将两者结合在一起,以使s3查找URL具有以下格式: https://[bucket-url]/user1-doc1
?
How can I combine the two so that the s3 lookup URL has the following format: https://[bucket-url]/user1-doc1
?
谢谢.
推荐答案
- 设置您的方法请求以接受路径参数{userid}和查询参数{docid}.
- 设置集成请求以接受
method.request.querystring.docid
和method.request.path.userid
作为URL路径参数. - 最后,将集成端点URL设置为
https://您的URL/ {userid}-{docid}
- Setup your Method Request to accept the path param {userid} and query param {docid}.
- Setup your Integration Request to accept both
method.request.querystring.docid
andmethod.request.path.userid
as URL path params. - Finally, setup your integration endpoint URL as https://your-url/{userid}-{docid}.
为此而挥霍的片段如下-
A swagger snippet for this is as follows-
"paths": {
"/concat-params/{userid}": {
"get": {
"parameters": [
{
"name": "userid",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "docid",
"in": "query",
"required": false,
"type": "string"
}
],
"responses": {...},
"x-amazon-apigateway-integration": {
"responses": {...},
"requestParameters": {
"integration.request.path.userid":"method.request.path.userid",
"integration.request.path.docid":"method.request.querystring.docid"
},
"uri": "https:.../{userid}-{docid}",
...
}
}
}
希望这会有所帮助,里蒂莎.
Hope this helps, Ritisha.
这篇关于AWS API Gateway:如何将多个方法请求参数合并为一个集成请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!