Skip to main content

Troubleshooting

Internal Server Error

There are multiple possible reasons for this error.

{
"message": "Internal Server Error"
}

Let's check all possible reasons.

Broken echo Lambda

You should look for the echo Lambda in AWS Console, go to the Test tab, and click the Test button. If you configured everything correctly, you should see something like this:

Testing lambda

Broken gate Lambda

You should look for the gate Lambda in AWS Console, go to the Test tab, and click the Test button.

Navigate to the Test tab in Lambda configuration and paste the following JSON to the Event JSON field:

{
"version": "2.0",
"type": "REQUEST",
"routeArn": "arn:aws:execute-api:us-east-1:123456:i6x4fg8hfc/test/GET/echo",
"routeKey": "GET /echo",
"rawPath": "/test/echo",
"rawQueryString": "",
"cookies": null,
"headers": {
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"authorization": "Bearer topsecret",
"cache-control": "no-cache, no-store, must-revalidate,max-age=0",
"content-length": "0",
"host": "i6x4fg8hfc.execute-api.us-east-1.amazonaws.com",
"pragma": "no-cache",
"x-forwarded-for": "127.0.0.1",
"x-forwarded-port": "443",
"x-forwarded-proto": "https"
},
"queryStringParameters": null,
"requestContext": {
"routeKey": "GET /echo",
"accountId": "123456789",
"stage": "test",
"requestId": "MX_NWiSDoAMEaRg=",
"apiId": "i6x4fg8hfc",
"domainName": "i6x4fg8hfc.execute-api.us-east-1.amazonaws.com",
"domainPrefix": "i6x4fg8hfc",
"time": "06/Oct/2023:10:19:13 +0000",
"timeEpoch": 1696587553924,
"http": {
"method": "GET",
"path": "/test/echo",
"protocol": "HTTP/1.1",
"sourceIp": "127.0.0.1",
"userAgent": "curl"
}
}
}

Now click the Test button. If everything works correctly, you should see the banner:

Testing lambda

When you extend the Details section, you should see logs and output from Gate Lambda.

Check gate Lambda logs

Ensure that logs are available in the Monitoring tab in the AWS Console for your Lambda function.

If logs are not visible, there may be two reasons for this:

  1. Gate is not called (for example, because API Gateway does not have permission to call gate Lambda).
  2. Gate can't write logs.

Let's start by checking the first option.

Try to detach the Lambda Authorizer

Try to disable the Lambda Authorizer in the AWS Console for the lambda_gateway API in Routes tab.

If it helped, it's likely that Gateway has no permissions to invoke the Lambda Authorizer. Please double check if gate has permission like:

Gate Lambda Policy 1 Gate Lambda Policy 2 Gate Lambda Policy 3

If it didn't help, it is likely that API Gateway does not have permission to call your Lambda.

The policy for your Lambda should be as follows

Echo Lambda Policy

Ensure that you have the proper aws_lambda_permission resource defined.

For Lambda:

resource "aws_lambda_permission" "lambda_permission" {
statement_id = "AllowExecutionFromAPIGateway"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.echo.function_name
principal = "apigateway.amazonaws.com"

source_arn = "${aws_apigatewayv2_api.lambda_gateway.execution_arn}/*/*"
}

For Lambda Authorizer:

resource "aws_lambda_permission" "authorizer_permission" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.gate.function_name
principal = "apigateway.amazonaws.com"

source_arn = "${aws_apigatewayv2_api.lambda_gateway.execution_arn}/authorizers/${aws_apigatewayv2_authorizer.gate.id}"
}

If logs are still not visible, ensure that all permissions are properly configured for your Lambda.

Try to re-create everything

Sometimes, AWS doesn't reflect changes in API Gateway configuration. This can be resolved by removing all resources and creating them again.

"Not Found" error

Ensure that the URL is correct. Remember to add /echo to the URL. So, for example, for https://i6x4fg8hfc.execute-api.us-east-1.amazonaws.com/testing you need to call https://i6x4fg8hfc.execute-api.us-east-1.amazonaws.com/testing/echo.