简体   繁体   中英

How to create a nested Resource path in AWS RestAPI using Cloudformation?

Can somebody explain the parentId property of aws resource type AWS::ApiGateway::Resource ? Documentation can be found here , Documentation is very much limited and only shows how to get the rootResourceId. Using that i was able to create the following structure. which gives me these paths.

/portfolio

/resource

/{resourceId}

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

Now my question is how to achieve structure like this where in {resourceId} is nested inside resource , so that my path looks like /resource/{resourceId} .

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

This is my template that create resources

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

The ParentId needs to reference the Resource you want to put it in.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM