LocalStack API Gateway Not Triggering Lambda Function from HTML Form Submission

21 Views Asked by At

I’m currently working on a Windows 11 local setup using LocalStack to simulate AWS services, and I’ve encountered an issue where my HTML form submission is not triggering the configured AWS Lambda function through the API Gateway. The setup works when I use the awslocal CLI to invoke the Lambda function directly, but not when submitting the form from a browser. Below are the details of my setup and the issue I’m facing:

Local Environment:

  • LocalStack running in a Docker container
  • API Gateway, Lambda, DynamoDB, and S3 services enabled
  • HTML form hosted on a local server (using Python’s http.server)

Lambda Function: The Lambda function is written in Python and is designed to process form submissions, parse the content, and store the data in a DynamoDB table. It works as expected when invoked directly with awslocal lambda invoke.

API Gateway: The API Gateway is set up to trigger the Lambda function on a POST request. The integration and method configurations appear correct when checked with awslocal apigateway get-method and awslocal apigateway get-integration.

HTML Form: The form uses POST method and is set to submit to the API Gateway endpoint URL. The form fields include fname, lname, and email. The action URL of the form is structured as follows (anonymized for privacy):

http://localhost:4566/{api-id}/prod/{resource}

Issue: When the form is submitted, the browser’s developer tools show a 200 OK response from the API Gateway, but the Lambda function does not seem to be triggered. The response headers indicate a Content-Type of text/plain; charset=utf-8 and a Content-Length of 0, suggesting that no response body is returned.

Attempts to Resolve:

  • Verified that the form’s action URL matches the API Gateway endpoint
  • Checked CORS settings in LocalStack’s docker-compose.yml file
  • Monitored network traffic using browser developer tools
  • Reviewed LocalStack logs for any error messages or clues

Logs: Here are some relevant logs from the LocalStack container when the form is submitted and when the Lambda function is invoked directly:

Form Submission Logs:

localstack-main  | 2024-03-23T19:42:23.199 DEBUG --- [   asgi_gw_1] rolo.gateway.wsgi          : POST localhost:4566/hma7zkncws/prod/meinformular
localstack-main  | 2024-03-23T19:42:23.200 DEBUG --- [   asgi_gw_1] l.aws.handlers.service     : no service set in context, skipping request parsing
localstack-main  | 2024-03-23T19:42:23.201  INFO --- [   asgi_gw_1] localstack.request.http    : POST /hma7zkncws/prod/meinformular => 200

Direct Lambda Invoke Logs:

localstack-main  | 2024-03-23T19:57:15.185 DEBUG --- [   asgi_gw_0] rolo.gateway.wsgi          : POST localhost:4566/2015-03-31/functions/KontaktFormularLambda/invocations
...

I would appreciate any insights or suggestions on what might be causing this issue and how to resolve it. Thank you in advance for your help!

0

There are 0 best solutions below