Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The API with ID does not include a resource with path /* having an integration LAMBDA on the ANY method

.net core serverless web api I am trying to do proxy integration with lambda and api gateway, everything is working fine with aws console

but i am facing issues with aws cli commands i tried integrating with cli but the lambda is not properly integrated

aws apigateway create-resource --rest-api-id id --parent-id id --path-part {proxy+}


aws apigateway put-method --rest-api-id id --resource-id id --http-method ANY --authorization-type "NONE" 


aws apigateway put-integration --rest-api-id id --resource-id id --http-method ANY --type HTTP_PROXY --integration-http-method ANY --uri arn:aws:apigateway:us-east-2:lambda:path//2015-03-31/functions/arn:aws:lambda:us-east-2:account_id:function:helloworld/invocations 


aws lambda add-permission --function-name helloworld --action lambda:InvokeFunction --principal apigateway.amazonaws.com --source-arn arn:aws:execute-api:us-east-2:account_id:apiid/*/*/* --statement-id 12345678
like image 296
Vman Avatar asked Jun 12 '19 16:06

Vman


People also ask

How do I return custom HTTP status codes from a Lambda function in Amazon API gateway?

The easiest way to set custom HTTP status code is to setup a Lambda Proxy Integration in API Gateway. In API Gateway > Resource > Actions Dropdown > Create Method > tick Lambda Proxy Integration and select appropriate Lambda function. For async functions just return with an object with statusCode and body .

How do I enable CORS on API gateway with Lambda proxy integration?

To enable CORS for the Lambda proxy integration, you must add Access-Control-Allow-Origin: domain-name to the output headers . domain-name can be * for any domain name. The output body is marshalled to the frontend as the method response payload.


1 Answers

There are two problems with your commands -

Incorrect

aws apigateway create-resource --rest-api-id id --parent-id id --path-part {proxy+}

Correct: Notice the double quotes

aws apigateway create-resource --rest-api-id id --parent-id id --path-part "{proxy+}"

Incorrect

aws apigateway put-integration \
    --rest-api-id id \
    --resource-id id \
    --http-method ANY \
    --type HTTP_PROXY \
    --integration-http-method ANY \
    --uri arn:aws:apigateway:us-east-2:lambda:path//2015-03-31/functions/arn:aws:lambda:us-east-2:account_id:function:helloworld/invocations 

Correct

  • type should be AWS_PROXY for Lambda Proxy Integrations.

  • integration-http-method should always be POST for Lambda Proxy integration, even if the http method is GET or ANY or anything else.

aws apigateway put-integration \
    --rest-api-id id \
    --resource-id id \
    --http-method ANY \
    --type AWS_PROXY \
    --integration-http-method POST \
    --uri arn:aws:apigateway:us-east-2:lambda:path//2015-03-31/functions/arn:aws:lambda:us-east-2:account_id:function:helloworld/invocations
like image 163
Sarthak Jain Avatar answered Nov 04 '22 02:11

Sarthak Jain