Question
A company uses a service to collect metadata from applications that the company hosts on premises. Consumer devices such as TVs and internet radios access the applications. Many older devices do not support certain HTTP headers and exhibit errors when these headers are present in responses. The company has configured an on-premises load balancer to remove the unsupported headers from responses sent to older devices, which the company identified by the User-Agent headers.
The company wants to migrate the service to AWS, adopt serverless technologies, and retain the ability to support the older devices. The company has already migrated the applications into a set of AWS Lambda functions.
Which solution will meet these requirements?
- A. Create an Amazon CloudFront distribution for the metadata service. Create an Application Load Balancer (ALB). Configure the CloudFront distribution to forward requests to the ALB. Configure the ALB to invoke the correct Lambda function for each type of request. Create a CloudFront function to remove the problematic headers based on the value of the User-Agent header. Correct
- B. Create an Amazon API Gateway REST API for the metadata service. Configure API Gateway to invoke the correct Lambda function for each type of request. Modify the default gateway responses to remove the problematic headers based on the value of the User-Agent header.
- C. Create an Amazon API Gateway HTTP API for the metadata service. Configure API Gateway to invoke the correct Lambda function for each type of request. Create a response mapping template to remove the problematic headers based on the value of the User-Agent. Associate the response data mapping with the HTTP API.
- D. Create an Amazon CloudFront distribution for the metadata service. Create an Application Load Balancer (ALB). Configure the CloudFront distribution to forward requests to the ALB. Configure the ALB to invoke the correct Lambda function for each type of request. Create a Lambda@Edge function that will remove the problematic headers in response to viewer requests based on the value of the User-Agent header.
Explanation
Option A is correct. CloudFront sits in front of an Application Load Balancer, and the ALB can use Lambda functions as targets, so the service stays serverless and each request type is routed to the right function. A CloudFront function associated with the viewer response event can read the viewer's request headers, including User-Agent, and remove the unsupported headers from the response before it reaches older devices. This replicates what the on-premises load balancer did.
Option B is incorrect because API Gateway gateway responses only customize responses that API Gateway itself generates (such as errors when a request fails to reach the integration); they do not alter successful responses from the Lambda integration.
Option C is incorrect because HTTP APIs do not support mapping templates; response mapping templates are a REST API feature.
Option D is incorrect because a Lambda@Edge function triggered on viewer requests runs before CloudFront forwards the request and cannot remove headers from the response. Response headers would have to be modified on a viewer response or origin response trigger.