AWS Certified Developer – Associate / Question #727 of 557

Question #727

A developer at a company recently built a serverless application to generate custom reports based on user-submitted data. The application’s user interface (UI) allows users to submit report generation requests and displays a confirmation message immediately. The application uses AWS Lambda functions for report processing, orchestrated by AWS Step Functions. The developer implemented an API using Amazon API Gateway integrated with Lambda to handle the UI requests.

The UI team reports that the API frequently returns timeout errors due to the computational complexity of generating large reports. The team requires the API to provide an instant confirmation response while the reports are processed in the background. Additionally, the backend must send an email notification to users once report generation is complete.

What should the developer do to reconfigure the API to meet these requirements?

A

Modify the API Gateway integration request to include an X-Amz-Invocation-Type header with a static value of 'Event'. Redeploy the API Gateway stage to implement the change.

B

Update the Lambda function configuration to set the reserved concurrency to 0, forcing asynchronous execution. Adjust the API Gateway timeout to match the Lambda timeout.

C

Increase the API Gateway timeout value to accommodate the Lambda function's execution time. Redeploy the API Gateway stage to apply the new timeout.

D

Add an X-Amz-Asynchronous header with a static value of 'true' to the API Gateway integration request. Redeploy the API Gateway stage to enable the change.

Explanation

Answer A is correct because setting the 'X-Amz-Invocation-Type' header to 'Event' in the API Gateway integration request enables asynchronous Lambda invocation. This decouples the API response from the Lambda function's execution time, allowing the API to return an immediate confirmation (HTTP 202) while the report generation runs in the background. Step Functions can then orchestrate the report processing and trigger an email notification via services like Amazon SNS upon completion.

Other options are incorrect:
- B: Setting reserved concurrency to 0 would block Lambda execution entirely, causing errors.
- C: Increasing API Gateway's timeout (max 29 seconds) does not resolve the root cause (long-running reports) and violates the requirement for instant confirmation.
- D: The correct header for asynchronous invocation is 'X-Amz-Invocation-Type', not 'X-Amz-Asynchronous'.

Key Points:
1. Asynchronous Lambda invocation via API Gateway avoids timeouts for long tasks.
2. Use 'X-Amz-Invocation-Type: Event' to trigger asynchronous execution.
3. Step Functions can manage background workflows and post-processing tasks like email notifications.

Answer

The correct answer is: A