AWS Certified Developer – Associate / Question #1027 of 557

Question #1027

A company uses Amazon API Gateway with an AWS Lambda integration for a backend process. The Lambda function must execute several sequential tasks that take up to 15 minutes to complete. Users report intermittent HTTP 504 errors from the API, but the Lambda logs show all invocations complete successfully.

Which solution will resolve the HTTP 504 errors?

A

Increase the timeout setting for the Lambda function.

B

Modify the Lambda function to use asynchronous invocation.

C

Configure the API Gateway to use an HTTP proxy integration.

D

Refactor the Lambda function to initiate an AWS Step Functions workflow.

Explanation

The correct answer is D because:

- API Gateway Timeout: API Gateway has a maximum integration timeout of 29 seconds. If the Lambda function takes longer (e.g., 15 minutes), API Gateway returns a 504 error, even if Lambda eventually succeeds.
- Step Functions Solution: Refactoring the Lambda function to start an AWS Step Functions workflow allows the Lambda to return immediately, passing control to Step Functions. Step Functions can handle long-running tasks (up to 1 year), avoiding API Gateway timeouts.

Why other options are incorrect:
- A: Increasing Lambda's timeout does not resolve API Gateway's 29-second limit.
- B: Asynchronous Lambda invocation would not return a response to the client via API Gateway, leading to incomplete HTTP requests.
- C: HTTP proxy integration does not change API Gateway's timeout limit.

Key Takeaway: For long-running tasks with API Gateway, offload work to Step Functions to avoid timeout errors.

Answer

The correct answer is: D