为什么无服务器在服务的 URL 中包含阶段名称?

问题描述 投票:0回答:1

我有一个使用

httpApi
(API网关V2)的项目。但是,如果我理解正确的话,只有 API Gateway 的版本 1 支持 gzip 压缩。

正确吗?

如果是这样,这让我有点困惑,因为新的 API 如何在功能上退化?

无论如何,如果是这种情况,如何防止无服务器框架通过插入暂存名称来破坏 URL?

POST - https://a0chsgxup2.execute-api.us-east-1.amazonaws.com/v1/collars/register # httpApi, no staging name on URL
GET - https://a0chsgxup2.execute-api.us-east-1.amazonaws.com/v1/flush/config # httpApi, no staging name on URL
GET - https://a0chsgxup2.execute-api.us-east-1.amazonaws.com/v1/flush/calories # httpApi, no staging name on URL
GET - https://a0chsgxup2.execute-api.us-east-1.amazonaws.com/unstable/v1/playground # http, staging name on URL (unstable)
aws-lambda serverless serverless-framework
1个回答
0
投票

AWS 已放弃 v1/v2 命名法,现在区分为 REST 与 HTTP。从他们的文档中可以看出:“REST API 比 HTTP API 支持更多的功能,而 HTTP API 的设计具有最少的功能,因此可以以更低的价格提供”。 https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html

所以,尽量不要把v2看成是v1的下一代。

REST API (v1) 的默认行为是在 URL 中包含阶段名称。解决这个问题的方法是创建自定义域名。请参阅:https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html

对于 HTTP api (v2),来自 AWS 文档:“您可以创建一个从 API URL 的基础提供服务的 $default 阶段,例如 https://{api_id}.execute-api.{region}。 amazonaws.com/。您使用此 URL 来调用 API 阶段。” https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-stages.html

默认行为与您所看到的不同。所以这不是来自 Serverless 框架,而是 AWS 本身。

HTTP api 更便宜,而 REST api 具有更多功能。我认为混合和匹配会非常困难,所以你可能最好选择一个 - 考虑到你的压缩需求,听起来你需要休息。

© www.soinside.com 2019 - 2024. All rights reserved.