DVA-C02 practice question 4 of 35

A company is expanding the compatibility of its photo-snaring mobile app to hundreds of additional devices with unique screen dimensions and…

Full set: 598 questions

Domain Deployment

A company is expanding the compatibility of its photo-snaring mobile app to hundreds of additional devices with unique screen dimensions and resolutions. Photos are stored in Amazon S3 in their original format and resolution. The company uses an Amazon CloudFront distribution to serve the photos The app includes the dimension and resolution of the display as GET parameters with every request. A developer needs to implement a solution that optimizes the photos that are served to each device to reduce load time and increase photo quality. Which solution will meet these requirements MOST cost-effective?
Answer options
A: Use S3 Batch Operations to invoke an AWS Lambda function to create new variants of the photos with the required dimensions and resolutions. Create a dynamic CloudFront origin that automatically maps the request of each device to the corresponding photo variant.
B: Use S3 Batch Operations to invoke an AWS Lambda function to create new variants of the photos with the required dimensions and resolutions. Create a Lambda@Edge function to route requests to the corresponding photo vacant by using request headers.
C: Create a Lambda@Edge function that optimizes the photos upon request and returns the photos as a response. Change the CloudFront TTL cache policy to the maximum value possible.
D: Create a Lambda@Edge function that optimizes the photos upon request and returns the photos as a response. In the same function store a copy of the processed photos on Amazon S3 for subsequent requests. Correct answer
Correct Answer:
D. Create a Lambda@Edge function that optimizes the photos upon request and returns the photos as a response. In the same function store a copy of the processed photos on Amazon S3 for subsequent requests.
Explanation

This solution is the most cost-effective and scalable for handling a large and unpredictable number of image variants. A Lambda@Edge function, triggered by an origin request in CloudFront, can process images on-the-fly based on the GET parameters. The crucial step for cost-effectiveness is storing the newly created image variant back into an Amazon S3 bucket. This ensures that the computationally expensive optimization process runs only once for each unique image size. Subsequent requests for the same variant, even after the CloudFront cache expires or from a different edge location, can be served directly from S3 without invoking the image processing logic again, thus saving significant compute costs over time.

Why Incorrect

A. Pre-processing all possible variants with S3 Batch Operations is not cost-effective. It generates high compute and storage costs for many variants that may never be requested.
B. This option also relies on pre-processing with S3 Batch Operations, which is inefficient and costly for hundreds of potential device dimensions for every single photo stored.
C. This approach is inefficient because the Lambda@Edge function would re-process the original image on every cache miss, leading to redundant compute operations and higher costs.

References

1. AWS Solutions Library

"Serverless Image Handler": This official AWS solution implements the exact pattern described in the correct answer. The documentation states

"The solution generates resized

optimized images on demand... It uses Amazon CloudFront to cache the generated images and serve them from the cache on subsequent requests." This confirms the on-demand processing and caching approach.

Source: AWS Solutions Library

Serverless Image Handler

Solution overview.

2. AWS Compute Blog

"Image resizing at scale with AWS Lambda and Amazon EFS": This blog post discusses on-the-fly image processing. While it uses a different trigger

it highlights the core principle: "The main benefit of this approach is that you only generate the image sizes that you need

when you need them. This saves on storage costs and processing time." This supports the on-demand model over pre-processing.

Source: AWS Compute Blog

May 18

2022

"Image resizing at scale with AWS Lambda and Amazon EFS".

3. Amazon CloudFront Developer Guide

"Example: Resizing an image": The official documentation provides an example of using a Lambda@Edge function triggered on an origin request to resize images. The logic involves checking if a resized image already exists in S3 before attempting to create it

which is the pattern in the correct answer.

Source: Amazon CloudFront Developer Guide

Section: "Lambda@Edge example functions"

Subsection: "Example: Resizing an image".

Scroll to Top