如何在AWS API Gateway中创建父资源?

时间:2016-03-06 07:57:58

标签: aws-api-gateway

使用AWS Api-Gateway服务时,我想添加“父”资源,而不删除和重建资源结构。具体来说,我想改变这个:

resource/name
resource/name

并向其添加“父”资源(v1),而不删除和重新构建两个“资源/名称”资源,如下所示:

/v1
  /resource/name
  /resource/name

如果需要使用CLI,示例命令会是什么样的?

更新:

感谢Ka Hou Ieong的精彩回答。以下是实施它的一些注意事项:

rest-api-id : Put the api id here. You can look it up with this command: aws apigateway get-rest-apis

resource-id : Put the id of the resource you'd like to move here. You can look it up with this command: aws apigateway get-resources --rest-api-id API-ID-HERE

replace : Leave this; it's the operation.

/parentId : Leave this. It refers to the "key" of the value that you'll replace.

<new parent resourceId> : Replace this with the ID of the parent you'd like.

1 个答案:

答案 0 :(得分:2)

您可以使用路径部分&#34; / v1&#34;创建资源,然后使用CLI工具或SDK重新使用这些资源。

示例cli命令重新显示资源

aws apigateway  update-resource \
    --rest-api-id rest-api-id \
    --resource-id resource-id \
    --cli-input-json "{\"patchOperations\" : [ 
          {
            \"op\" : \"replace\",
            \"path\" : \"/parentId\",
            \"value\" : \"<new parent resourceId>\"
          } 
    ]}"

以下是cli工具文档:http://docs.aws.amazon.com/cli/latest/reference/apigateway/update-resource.html

以下是API参考:http://docs.aws.amazon.com/apigateway/api-reference/link-relation/resource-update/