What should the developer do to configure the API to meet these requirements?
Change the API Gateway route to add an X-Amz-Invocation-Type header with a static value of ‘Event’ in the integration request. Deploy the API Gateway stage to apply the changes.
Change the configuration of the Lambda function that implements the request to process a file. Configure the maximum age of the event so that the Lambda function will run asynchronously.
Change the API Gateway timeout value to match the Lambda function timeout value. Deploy the API Gateway stage to apply the changes.
Change the API Gateway route to add an X-Amz-Target header with a static value of ‘Async’ in the integration request. Deploy the API Gateway stage to apply the changes.
Explanations:
By setting the X-Amz-Invocation-Type header to ‘Event’ in the API Gateway integration request, the Lambda function is invoked asynchronously. This allows the API to return an immediate response to the UI while the Lambda function continues processing the file in the background. This solution meets the requirement of providing an immediate response and sending an email once the processing is complete.
Configuring the Lambda function to run asynchronously by setting the maximum age of the event does not directly solve the issue of returning an immediate response to the UI. The problem lies in how the API Gateway handles the request, not the Lambda function configuration.
Changing the API Gateway timeout to match the Lambda function timeout does not resolve the timeout issue. API Gateway still waits for the Lambda function to complete, which leads to timeout errors. Asynchronous invocation is needed to provide an immediate response.
Adding the X-Amz-Target header with a value of ‘Async’ is not a valid configuration for invoking Lambda functions asynchronously. The correct approach is to use the ‘Event’ invocation type in the X-Amz-Invocation-Type header.