简体   繁体   English

具有未定义阶段的 AWS Api 网关自定义域名

[英]AWS Api Gateway Custom Domain Name with undefined stage

I'm trying to set up a Custom Domain Name in AWS API Gateway where callers have to specify explicitly the stage name after any base path name .我正在尝试在 AWS API 网关中设置自定义域名,其中调用者必须在任何基本路径名之后明确指定阶段名称 It is something I did in the past but now it seems that, since AWS updated the console interface, it is no more possible.这是我过去做过的事情,但现在看来,由于 AWS 更新了控制台界面,这不再可能了。 The final url should be like:最终的 url 应该是这样的:

https://example.com/ {basePath}/{stage}/function https://example.com/ {basePath}/{stage}/function

  • I tried using the console, but stage is now a mandatory field (chose from a drop-down).我尝试使用控制台,但阶段现在是必填字段(从下拉列表中选择)。
  • I tried using AWS CLI, but stage is again a mandatory field我尝试使用 AWS CLI,但 stage 又是一个必填字段
    aws: error: the following arguments are required: --stage

  • I tried using Boto3, following the documentation ( https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/apigateway.html#APIGateway.Client.create_base_path_mapping ) but, even if stage can be specified as 'none' ( The name of the API's stage that you want to use for this mapping. Specify '(none)' if you want callers to explicitly specify the stage name after any base path name. ), doing this returns an error:我尝试使用 Boto3,遵循文档( https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/apigateway.html#APIGateway.Client.create_base_path_mapping )但是,即使阶段可以指定为'none'(您要用于此映射的 API 阶段的名称。如果您希望调用者在任何基本路径名之后显式指定阶段名称,请指定“(无)”。 ),这样做会返回错误:
    botocore.errorfactory.BadRequestException: An error occurred (BadRequestException) when calling the CreateBasePathMapping operation: Invalid stage identifier specified

What is funny (or frustrating) is that I have some custom domain names created with the old console and that are perfectly working, without any stage defined.有趣(或令人沮丧)的是,我有一些使用旧控制台创建的自定义域名,并且运行良好,没有定义任何阶段。

It is still possible to specify only the "API ID" and "Path" and leave out the "stage" parameter.仍然可以仅指定“API ID”和“路径”而省略“阶段”参数。 I have tried this both from the console and the CLI:我从控制台和 CLI 都试过了:

  • From console: The "Stage" setting is a drop-down as you mentioned, but can be left blank (don't select anything).从控制台:“阶段”设置是您提到的下拉菜单,但可以留空(不要 select 任何东西)。 If you did select a stage, delete the API mapping and add it again如果你做了 select 一个阶段,删除 API 映射并重新添加它

  • From CLI: Just tried this as well and works fine for me on CLI version aws-cli/1.18.69 Python/3.7.7 Darwin/18.7.0 botocore/1.16.19来自 CLI:刚刚也尝试过,并且在 CLI 版本aws-cli/1.18.69 Python/3.7.7 Darwin/18.7.0 botocore/1.16.19

$ aws apigateway create-base-path-mapping --domain-name **** --rest-api-id *** --base-path test
{
    "basePath": "test",
    "restApiId": "***"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM