2016-09-30 31 views
4

我需要使用aws客戶端創建api網關。我可以通過使用Web控制檯來創建和集成我的aws-lambda函數。但是iam與aws-client混淆了。這些是我遵循的步驟。使用aws-cli創建api-gateway lambda集成

  1. 創建api網關,並使用Web控制檯與我的示例lambda函數集成。

enter image description here

  • 部署創建的API和出口爲JSON文件。
  • 使用aws-cli使用導出的json文件創建新的api網關。像這樣的命令。

    aws apigateway import-rest-api --body file://tmpfile.json --region us-east-1; 
    
  • 但是隻創造了資源的開發&方法。

    1. 將api方法與我的lambda函數集成在一起。我執行命令,這樣

      aws apigateway put-integration --rest-api-id 42ku123id8u3a --resource-id core-api-dev --http-method DELETE --type AWS --integration-http-method POST --uri 'arn:aws:lambda:us-east-1:my-lambda-function-arn' --region us-east-1 
      

      但它產生這樣

    An error occurred (NotFoundException) when calling the PutIntegration operation: Invalid Resource identifier specified

    錯誤消息是可以集成使用AWS客戶現有的lambda函數API網關的方法?什麼是資源標識符?

    +0

    該文檔有一個示例lambda集成:http://docs.aws.amazon.com/cli/latest/reference/apigateway/put-integration.html – mttdbrd

    回答

    1

    可以運行aws apigateway get-resources得到resource-id

    aws apigateway get-resources --rest-api-id 42ku123id8u3a --region us-east-1 
    

    它會返回一個JSON像

    { 
        "items": [ 
         { 
          "path": "/resource/xxx", 
          "resourceMethods": { 
           "POST": {} 
          }, 
          "id": "_yourresourceid_", 
          "pathPart": "xxx", 
          "parentId": "ai5b02" 
         } 
        ] 
    } 
    

    你可以從這個JSON採取ID,並用它在你的命令aws apigateway put-integration

    +0

    所以我確實做到了,但仍然得到錯誤:An調用PutIntegration操作時發生錯誤(NotFoundException):指定了無效的方法標識符 – Atifm

    1

    理想情況下,您應該在第2步中將JSON導出爲集成擴展離子。在控制檯中有3種導出類型的選項,中間的將包括導出中的集成和授權者。然後,當您導入時,您將擁有集成。