1

有人可以解釋parentId aws資源類型的屬性AWS :: ApiGateway :: Resource? 文檔可以找到here,文檔非常有限,只顯示如何獲取rootResourceId。使用我可以創建以下結構。這給了我這些路徑。如何使用Cloudformation在AWS RestAPI中創建嵌套的資源路徑?

/組合

/資源

/{RESOURCEID}

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

現在我的問題是如何實現結構類似這樣的地方在{resourceId}嵌套在資源內,以便我的路徑看起來像/resource/{resourceId}

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

回答

1

的的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}" 
    } 
}, 
+0

是,居然想通出來,當我檢查無服務器編譯腳本,同時嘗試通過傳遞'Ref'作爲'ref'來做一個愚蠢的錯誤。謝謝! – Veer3383