You've been given the requirement to customize the content which is distributed to users via a Cloudfront Distribution.
The content origin is an S3 bucket.
How could you achieve this?
Click on the arrows to vote for the correct answer
A. B. C. D.Answer - C.
The AWS Documentation mentions the following.
Lambda@Edge is an extension of AWS Lambda, a compute service that lets you execute functions that customize the content that CloudFront delivers.
You can author functions in one region and execute them in AWS locations globally closer to the viewer, without provisioning or managing servers.
Lambda@Edge scales automatically, from a few requests per day to thousands per second.
Processing requests at AWS locations closer to the viewer than on origin servers significantly reduces latency and improves the user experience.
Option A is incorrect because although adding an event to the S3 bucket and then invoking the event by the Lambda function to customize the content may do the needful, a lot of manual intervention is required.
With Lambda @ Edge, it can be done more easily.
Option B is incorrect because Step Function is normally used to sequence AWS Lambda functions and multiple AWS services.
This scenario is not suitable.
Option D is incorrect because adding EC2 is not cost-efficient.
For more information on Lambda@Edge, please refer to the below Link-
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-at-the-edge.htmlThe correct answer for this question is option C, "Consider using Lambda@Edge."
Lambda@Edge is a serverless computing service provided by AWS that allows developers to run custom code in response to events generated by Amazon CloudFront. With Lambda@Edge, you can write and deploy code to modify and customize content delivered through CloudFront.
To customize the content distributed to users via a CloudFront Distribution, you can create a Lambda@Edge function that modifies the content at the edge location before it is delivered to the end-user. You can attach this Lambda function to your CloudFront Distribution and configure it to run whenever a viewer requests content from your distribution.
This solution is much simpler and more efficient than the other options listed.
Option A, "Add an event to the S3 bucket. Make the event invoke a Lambda function that would customize the content," requires additional setup and configuration. You would need to create an event notification in S3 to trigger the Lambda function, and you would need to ensure that the Lambda function has access to modify the content in the S3 bucket.
Option B, "Add a Step Function. Add a step with a Lambda function just before the content gets delivered to the users," is also possible, but it is more complex and requires more configuration. You would need to create a Step Function that includes a Lambda function that modifies the content, and you would need to configure CloudFront to use the Step Function to modify the content.
Option D, "Consider using a separate application on an EC2 Instance for this purpose," is also possible, but it requires you to manage the EC2 instance, which can be time-consuming and costly. Additionally, using an EC2 instance for this purpose is overkill when a serverless solution like Lambda@Edge is available.