Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create api-gateway lambda integration using aws-cli

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

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

enter image description here

  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 resources & 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 produces 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?

like image 563
Abdul Manaf Avatar asked Sep 30 '16 09:09

Abdul Manaf


2 Answers

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

like image 92
Frederic Henri Avatar answered Oct 14 '22 02:10

Frederic Henri


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.

like image 43
jackko Avatar answered Oct 14 '22 00:10

jackko