Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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}"
        }
    },
like image 595
Veer3383 Avatar asked Sep 15 '17 10:09

Veer3383


1 Answers

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}"
  }
},
like image 172
jens walter Avatar answered Sep 18 '22 13:09

jens walter