Question:
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.
- Create api gateway and integrate with my sample lambda function using web console.
- Deploy created api and export as json file.
- Create new api gateway using exported json file using aws-cli. Command like this.
12aws apigateway import-rest-api --body file://tmpfile.json --region us-east-1;
But it created only resources & methods.
- For integrate api method with my lambda function, I execute command like this
12aws 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?
Answer:
you can run aws apigateway get-resources
to get the resource-id
1 2 |
aws apigateway get-resources --rest-api-id 42ku123id8u3a --region us-east-1 |
It will return a JSon like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
{ "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