【问题标题】:How to create a nested Resource path in AWS RestAPI using Cloudformation?如何使用 Cloudformation 在 AWS RestAPI 中创建嵌套资源路径?
【发布时间】:2018-02-24 11:47:12
【问题描述】:

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

/投资组合

/资源

/{resourceId}

/
 /portfolio
   GET
   OPTIONS
 /resource
   GET
   OPTIONS
 /{resourceId}
   GET
   OPTIONS

现在我的问题是如何实现这样的结构,其中 {resourceId} 嵌套在 resource 中,这样我的路径看起来像 /resource/{资源ID} .

/
 /portfolio
   GET
   OPTIONS
 /resource
   GET
   OPTIONS
   /{resourceId}
     GET
     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}"
        }
    },

【问题讨论】:

    标签: amazon-web-services aws-api-gateway amazon-cloudformation


    【解决方案1】:

    ParentId 需要引用你要放入的 Resource。

    "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}"
      }
    },
    

    【讨论】:

    • 是的,当我检查无服务器编译脚本时,实际上发现了这一点,同时尝试将 'Ref' 传递为 'ref' 犯了一个愚蠢的错误。谢谢!
    猜你喜欢
    • 2020-08-30
    • 1970-01-01
    • 2019-08-27
    • 1970-01-01
    • 2017-07-11
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多