skip to Main Content

I’m facing an issue with the AWS API Gateway and Lambda integration. I have a Terraform configuration that sets up an API Gateway with a Lambda proxy integration. The type in aws_api_gateway_integration is set to "AWS_PROXY". However, when I test the API endpoint using Postman, I receive an internal server error.

Interestingly, when I unchecked and checked the "Use Lambda Proxy integration" option in the API Gateway console, the endpoint started working fine, returning a 200 response. But I want to understand the underlying cause of the issue and ensure a consistent configuration.

Here’s what I have already checked:

  • The Terraform configuration includes the correct type value for the aws_api_gateway_integration resource.
  • The Lambda function handles the incoming event correctly and returns a valid response when invoked directly.
  • I have confirmed that all API Gateway resources are successfully deployed.

Is there something I might be missing or any other configuration I need to consider? Any insights into why unchecking and checking the "Use Lambda Proxy integration" option resolved the internal server error would be greatly appreciated.

Thank you in advance for your help!

and here is the terraform "aws_api_gateway_integration" resource detail code :

resource "aws_api_gateway_integration" "ok_integration" {
  rest_api_id             = aws_api_gateway_rest_api.api_gateway_rest_api_ok.id
  resource_id             = aws_api_gateway_resource.product_resource.id
  http_method             = aws_api_gateway_method.method_resource.http_method
  integration_http_method = "POST"
  type                    = "AWS_PROXY"
  uri                     = aws_lambda_function.lambda_function_ok.invoke_arn
}

and this is my lambda function :

exports.handler = async (event) => {
    console.log("Lambda function invoked successfully");
    
    // Process the event or perform any desired actions
    // ...
  
    const response = {
      statusCode: 200,
      body: "OK",
    };
    return response;
  };

2

Answers


  1. Please note that your API gateway needs to proxy the request properly through to the Lambda Function.

    Check out and investigate if you have properly set up the greedy path parameter on the Lambda Proxy endpoint.

    Kudos for using IaC principals, debugging in the UI might save you time here to figure out the issue.

    Login or Signup to reply.
  2. did you find a reason and a solution? I’m facing the same issue.

    Thanks,

    Vincenzo.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search