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

How to create a parent resource in AWS API Gateway?

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

resource/name
resource/name

并在不删除和重新制作两个 "resource/name" 资源的情况下向其添加 "parent" 资源 (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.

您可以创建路径部分为“/v1”的资源,然后使用 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/