amazon-web-services - Versioning using base path mappings in AWS API Gateway
问题描述
I have a pretty straightforward stack: API Gateway sitting in front of a lambda. Currently my paths looks something like:
/dogs
, /dogs/{id}
, etc.
All I want to do is add a version to the base path (i.e. api.dogs.com/v1/dogs
). I tried doing this by creating a custom domain name with a base path mapping of v1 pointing to my stage in API Gateway.
This routes just fine through API Gateway but has issues once it hits the routing logic in my lambda. My lambda is expecting /dogs
but with the base path mapping the path is actually v1/dogs
.
What's a good way to approach this? I want to get away from having to deal with versions directly in my code (lambda) if possible.
解决方案
在event
您的 lambda 函数接收的对象中,您实际上应该找到所有需要的信息,无论是否有版本控制:
event = {
"resource": "/hi",
"path": "/v1/hi",
"requestContext": {
"resourcePath": "/hi",
"path": "/v1/hi",
....
},
....
}
只需调整路由器逻辑中的代码以访问所需的属性即可解决您的问题,并且无需再次关注代码中的版本控制。
推荐阅读
- android - Android : mkdir() /mkdir() 在辅助外部存储上返回 false
- duplicates - 删除重复项:意外的 Sparql 示例行为,缺少结果
- vue.js - Mapbox GL this.map.on('load') 事件在本地有效,但在我部署到 vercel 时无效
- python-3.x - 如何使用 docplex 安装 CP Optimizer 20.1?
- python - 可以将 Python 中函数的输出作为列添加到数据框中吗
- python - 在 Python 中使用 pandas 格式化列
- class - 两个类 Kotlin 之间的双向通信
- r - 如何根据另一列计算一列中的值之间的差异?
- c++ - 无法在 vscode 终端中编译 .cpp
- c# - 即使启用了 broadFileSystemAccess,访问文件也有问题