AWS API Gateway debugging notes

Internal server error but no logs?

Wiring up a Lambda function to API Gateway takes a few steps. If you miss one the route to your function won’t be complete and API Gateway will drop your request (or message if you’re using WebSockets).

Make sure you do all of these steps:

  • Create a Lambda function (in CDK’s Lambda module this is new Function(...) which requires:
    • id an identifier for the function
    • FunctionProps the properties used to build the function
  • Create an integration (in CDK’s API Gateway v2 module this is new CfnIntegration(...) which requires:
    • apiId - in CDK it is api.ref if the new CfnApi(... call’s result was stored in a variable called api
    • integrationType - usually AWS_PROXY
    • integrationUri - an API Gateway ARN that contains the ARN of the Lambda function it is using like this arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:512341234123:function:myfunction-EB2081F1-4R5RskdFGSYU/invocations
    • credentialsArn - the ARN of a role that can be assumed by the service principal
  • Create a route (in CDK’s API Gateway v2 module this is new CfnRoute(... step) which requires:
    • apiId - same as above
    • routeKey - which is the path that API Gateway should use to filter requests/messages for this integration
    • authorizationType - NONE for no authorization, but there are many other options
    • target - in TypeScript CDK it is integrations/${integration.ref} if the new CfnIntegration(... call from above was stored in a variable called integration

If that doesn’t work make sure you have API Gateway logging turned on and see if your requests are getting routed to another integration.