A developer exposes a report feature through an Amazon API Gateway REST API that uses a Lambda non-proxy (custom) integration. The function builds a PDF in 2-4 minutes and emails a link when it is done. Clients receive 504 errors, although every report is eventually emailed. The client only needs an acknowledgement that the request was accepted. Which change requires the least code?
Choose one.
API Gateway can invoke a Lambda non-proxy integration asynchronously so the API returns at once.
The client only needs an acknowledgement, so the work does not belong in the request/response path. API Gateway's integration timeout (29 seconds by default) is well below the build time, so any synchronous design returns 504. In a Lambda non-proxy integration, mapping the X-Amz-Invocation-Type header to 'Event' makes API Gateway use asynchronous invocation, which returns at once and needs no function code change. A longer Lambda timeout or a 202 sent after the build both leave the call synchronous.
- Find where the 504 comes from: the API Gateway integration timeout, not Lambda.
- Note that the client needs only an acknowledgement, so asynchronous processing fits.
- Recall that a non-proxy Lambda integration can request asynchronous invocation through the X-Amz-Invocation-Type header.
- Reject changes that keep the invocation synchronous.
Exam tip: Long work behind API Gateway: invoke it asynchronously and acknowledge, rather than make the client wait.
DVA-C03 Application Development: Decoupling, APIs, SDKs, Events, Streams and AI — the lesson that teaches this.