AWS API Gateway: forcing a 200OK response, while passing data to backend (python39 lambda) for handling?


Hi all,

I'm getting stuck on a problem of how to properly handle a POST request from a 3rd party (webhook) who expects an immediate 200OK response upon receiving the message or it resends.

I have handled issues like this in the past with the inclusion of a lambda that the API points to pushing the message to a que system (SQS), and returning 200OK once that is complete. While w/e backend processes needed to run, can handle their business in peace. Is there no way, at the API gateway level, or directly in the lambda, to force a status response without waiting for the lambda to return a response when it's completed it's run? Is this just the standard to decouple the response message from the backend?

1 Answer
Accepted Answer

You can consider using the following design patterns:

  1. Use AWS Integration target for API Gateway, so that it will send messages directly to an SQS queue and have Lambda function to be triggered from that queue for message processing. See Amazon API Gateway to SQS to Lambda pattern, for example.
  2. You can leverage Lambda Asynchronous invocation capability with API Gateway's Lambda Integration as described here: Set up asynchronous invocation of the backend Lambda function.

The difference between option 1 and 2 is that SQS queue for the option 2 is managed internally by Lambda runtime and you have less control over its configuration.

That way, API Gateway will respond to the caller without waiting for Lambda to complete its execution.

answered 2 years ago
  • #1 is the path I ended up going with. Setting up an API that receives a post request to a "/events" endpoint and a simple proxy to handle events that do not match a pattern for the API. Lambda setup to trigger off the SQS and any failed or stale messages are pushed to a Dead Letter Que for further handling / reporting.

    Setup this way I get proper response times when handling webhook responses while still giving the longer running lambdas time to process.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions