【问题标题】:what is the --rest-api-id and --resource-id and where do i find them?什么是 --rest-api-id 和 --resource-id 我在哪里可以找到它们?
【发布时间】:2018-09-21 15:30:44
【问题描述】:

我想运行这个命令:https://docs.aws.amazon.com/cli/latest/reference/apigateway/test-invoke-method.html

它需要这两个字段,找不到任何文档,它们是:

aws apigateway test-invoke-method --rest-api-id 1234123412 --resource-id avl5sg8fw8 --http-method GET --path-with-query-string '/'

我的 API 网关端点如下所示:

https://abc123.execute-api.us-east-1.amazonaws.com/MyStage/

我只看到那里的唯一标识符 - 但这个命令似乎需要两个 ID。在 API Gateway 控制台的什么位置可以找到它们?

【问题讨论】:

    标签: amazon-web-services aws-lambda aws-api-gateway aws-cli


    【解决方案1】:

    您的 rest-api-id 是端点 URL 中“execute-api”之前的标识符。

    在您的示例网址中:

    https://abc123.execute-api.us-east-1.amazonaws.com/MyStage/
    

    rest-api-idabc123

    可以通过 CLI 使用 get-resources 调用和 rest-api-id 获取资源 ID:

    > aws apigateway get-resources --rest-api-id abc123
    {
    "items": [
        {
            "id": "xxxx1",
            "parentId": "xxxx0",
            "pathPart": "foo",
            "path": "/foo",
            "resourceMethods": {
                "GET": {}
            }
        },
        {
            "id": "xxxx0",
            "path": "/"
        }
    ]}
    

    items 属性中的每条记录都是一个资源,其id 属性是一个资源 ID,您可以在 test-invoke-method 中与与该资源关联的方法一起使用。

    当您选择一个端点/资源时,这两个值都会在控制台顶部显示:

    【讨论】:

    • 您可以使用以下命令行获取所有 ID 的列表:aws apigateway get-rest-apis。注意:您可以为区域等提供额外的参数。
    【解决方案2】:

    这里是你可以使用的 bash 脚本的一部分,假设你安装了 jq 来解析 json 并且只有一个 API。它从 items 数组中获取第一个 API ID,然后查找该资源 ID,然后使用 POST 调用 API:

    API_ID=`aws apigateway get-rest-apis | jq -r ".items[0].id"` 
    RESOURCE_ID=`aws apigateway get-resources --rest-api-id $API_ID | jq -r ".items[].id"`  
    aws apigateway test-invoke-method --rest-api-id $API_ID --resource-id $RESOURCE_ID --http-method POST
    

    【讨论】:

      猜你喜欢
      • 2015-09-02
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 2017-01-26
      • 1970-01-01
      • 1970-01-01
      • 2020-09-28
      • 2017-01-08
      相关资源
      最近更新 更多