如何在 AWS API 网关中映射 WSGI 响应
How to map WSGI responses in AWS API Gateway
我使用 aws-wsgi 将 Flask 应用程序部署到 AWS Lambda。我在 AWS API 网关中创建了几个资源并将它们的方法映射到我的 lambda。我现在可以 POST/GET 这些资源,我得到 "a response"(见下文)。我知道此响应符合某些 WSGI 标准,但我想将其翻译为 "just a response"。现在我的端点 return JSON 但我想灵活地支持我的 Flask 应用程序可能 return 的其他内容类型。如何在 API 网关的响应中配置映射以适当地重新格式化响应?我有默认的 "Integration Response"(输出直通:是)但我不知道在 "Method Response".
中做什么
这是我收到的回复:
{
"isBase64Encoded": false,
"statusCode": "200",
"headers": {
"Content-Type": "application/json",
"Content-Length": "47"
},
"body": "{\n \"key1\": 1, \n \"key2\": 3, \n \"key3\": 2\n}\n"
}
我正在使用 Flask 和 aws-wsgi (https://pypi.org/project/aws-wsgi/) for no particular reason, I saw there are other similar projects (e.g. https://github.com/adamchainz/apig-wsgi),我愿意尝试替代方案。
在 "Integration Request" 下勾选 "Use Lambda Proxy integration"。
我使用 aws-wsgi 将 Flask 应用程序部署到 AWS Lambda。我在 AWS API 网关中创建了几个资源并将它们的方法映射到我的 lambda。我现在可以 POST/GET 这些资源,我得到 "a response"(见下文)。我知道此响应符合某些 WSGI 标准,但我想将其翻译为 "just a response"。现在我的端点 return JSON 但我想灵活地支持我的 Flask 应用程序可能 return 的其他内容类型。如何在 API 网关的响应中配置映射以适当地重新格式化响应?我有默认的 "Integration Response"(输出直通:是)但我不知道在 "Method Response".
中做什么这是我收到的回复:
{
"isBase64Encoded": false,
"statusCode": "200",
"headers": {
"Content-Type": "application/json",
"Content-Length": "47"
},
"body": "{\n \"key1\": 1, \n \"key2\": 3, \n \"key3\": 2\n}\n"
}
我正在使用 Flask 和 aws-wsgi (https://pypi.org/project/aws-wsgi/) for no particular reason, I saw there are other similar projects (e.g. https://github.com/adamchainz/apig-wsgi),我愿意尝试替代方案。
在 "Integration Request" 下勾选 "Use Lambda Proxy integration"。