首页 文章

如何使用Cloudformation在AWS RestAPI中创建嵌套的资源路径?

提问于
浏览
2

有人可以解释aws资源类型 AWS::ApiGateway::ResourceparentId 属性吗?文档可以找到here,文档非常有限,只显示如何获取rootResourceId . 使用它我能够创建以下结构 . 这给了我这些路径 .

/portfolio

/resource

/

/
/组合
得到
OPTIONS
/资源
得到
OPTIONS
/

得到
OPTIONS

现在我的问题是如何实现这样的结构 嵌套在 resource 中,以便我的路径看起来像 /resource/ .

/
/组合
得到
OPTIONS
/资源
得到
OPTIONS
/

得到
OPTIONS

这是我创建资源的模板

"getPortfoliosResource": {
        "Type": "AWS::ApiGateway::Resource",
        "Properties": {
            "RestApiId": {
                "Ref": "myAPI"
            },
            "ParentId": {
                "Fn::GetAtt": ["myAPI", "RootResourceId"]
            },
            "PathPart": "portfolios"
        }
    },
    "getResourcesResource": {
        "Type": "AWS::ApiGateway::Resource",
        "Properties": {
            "RestApiId": {
                "Ref": "myAPI"
            },
            "ParentId": {
                "Fn::GetAtt": ["myAPI", "RootResourceId"]
            },
            "PathPart": "resources"
        }
    },
   "getResourceid": {
        "Type": "AWS::ApiGateway::Resource",
        "Properties": {
            "RestApiId": {
                "Ref": "epmoliteAPI"
            },
            "ParentId": {
                "Fn::GetAtt": ["epmoliteAPI", "RootResourceId"]
            },
            "PathPart": "{resourceId}"
        }
    },

1 回答

  • 3

    ParentId需要引用您要将其放入的资源 .

    "getPortfoliosResource": {
      "Type": "AWS::ApiGateway::Resource",
      "Properties": {
          "RestApiId": {
              "Ref": "myAPI"
          },
          "ParentId": {
              "Fn::GetAtt": ["myAPI", "RootResourceId"]
          },
          "PathPart": "portfolios"
      }
    },
    "getResourcesResource": {
      "Type": "AWS::ApiGateway::Resource",
      "Properties": {
          "RestApiId": {
              "Ref": "myAPI"
          },
          "ParentId": {
              "Fn::GetAtt": ["myAPI", "RootResourceId"]
          },
          "PathPart": "resources"
      }
    },
    "getResourceid": {
      "Type": "AWS::ApiGateway::Resource",
      "Properties": {
          "RestApiId": {
              "Ref": "myAPI"
          },
          "ParentId": {
              "Ref": "getResourcesResource"
          },
          "PathPart": "{resourceId}"
      }
    },
    

相关问题