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

0

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개 답변
1
수락된 답변

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.

AWS
답변함 2년 전
  • #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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠