Create api-gateway lambda integration using aws-cli

北战南征 提交于 2020-01-14 09:36:06

问题


i need to create an api gateway using aws client. i suucessfully create and integrate with my aws-lambda function using web console. But iam confused with aws-client. These are the steps i followed.

  1. create api gateway and integrate with my sample lambda function using web console.

  1. Deploy created api and export as json file.
  2. Create new api gateway using exported json file using aws-cli. command like this.

    aws apigateway import-rest-api --body file://tmpfile.json --region us-east-1;
    

But it created only resourses & methods.

  1. for integrate api method with my lambda function. i execute command like this

    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
    

    But it produce error message like this

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

Is it possible to integrate api gateway method with existing lambda function using aws client? what is Resource identifier ?


回答1:


you can run aws apigateway get-resources to get the resource-id

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

It will return a JSon like

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

you can take the id from this JSon and use it on your command for aws apigateway put-integration




回答2:


Ideally you should export as JSON in step 2 'with integration extensions'. In the console there are 3 options for export type, and the middle one will include the integrations and authorizers in the export. Then when you import you'll have the integrations already.



来源:https://stackoverflow.com/questions/39788094/create-api-gateway-lambda-integration-using-aws-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!