A photo-sharing app stores original images in Amazon S3 and serves them through CloudFront. Each mobile device sends its display dimensions and resolution as GET parameters. To serve optimized images per device and improve load time and quality cost-effectively, which solution is best?
Choose an answer
Tap an option to check your answer.
Correct answer: Use a Lambda@Edge function to optimize images on demand and return the image in the response, and have that same function save the processed image to Amazon S3 for subsequent requests..
Why this is the answer
The correct solution uses a Lambda@Edge function to optimize images on demand and cache them. When a request for an optimized image comes in, Lambda@Edge can resize the original S3 image based on the device's parameters. This optimized image is then returned to the user and simultaneously saved back to S3. Subsequent requests for the same optimized image will be served directly from S3 via CloudFront's cache, improving performance and reducing Lambda@Edge invocations. The other options are less efficient: Pre-generating all variants with S3 Batch Operations and Lambda is costly and complex due to the vast number of possible device dimensions. A dynamic CloudFront origin mapping is also not a standard or efficient pattern. Using S3 Batch Operations to pre-generate variants and then Lambda@Edge to route requests is inefficient because it still requires pre-generation of all variants, which is impractical for dynamic resizing. Using Lambda@Edge to optimize on demand and setting CloudFront TTL to maximum without saving to S3 means every request for a unique variant will invoke the Lambda, increasing cost and latency for uncached variants.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed