18 - Lambda @ Edge Flashcards
1
Q
Lambda@Edge
A
- Allows you to run code across AWS locations globally without provisioning or managing servers responding to end-users at the lowest network latency.
- Just upload your Node.js or Python code to AWS Lambda and configure your function to be triggered in response to Amazon CloudFront requests
- (i.e., when a viewer request lands, when a request is forwarded to or received back from the origin, and right before responding back to the end-user).
- The code is then ready to execute across AWS locations globally when a request for content is received
- Scales with the volume of CloudFront requests globally. Learn more in our documentation.
2
Q
Performance
A
- optimized for latency-sensitive use cases where your end viewers are distributed globally.
- All the information you need to make a decision should be available at the CloudFront edge, within the function and the request.
3
Q
Lambda@Edge is triggered:
A
- When CloudFront receives a request from a viewer (viewer request)
- Before CloudFront forwards a request to the origin (origin request)
- When CloudFront receives a response from the origin (origin response)
- Before CloudFront returns the response to the viewer (viewer response)
4
Q
Use Cases
A
- A Lambda function can inspect cookies and rewrite URLs so that users see different versions of a site for A/B testing.
- CloudFront can return different objects to viewers based on the device they’re using by checking the User-Agent header, which includes information about the devices.
- For example, CloudFront can return different images based on the screen size of their device.
- Similarly, the function could consider the value of the Referer header and cause CloudFront to return the images to bots that have the lowest available resolution.
- Or you could check cookies for other criteria.
- For example, on a retail website that sells clothing, if you use cookies to indicate which color a user chose for a jacket, a Lambda function can change the request so that CloudFront returns the image of a jacket in the selected color.
5
Q
Integrations
A
- A Lambda function can generate HTTP responses when CloudFront viewer request or origin request events occur.
- A function can inspect headers or authorization tokens, and insert a header to control access to your content before CloudFront forwards the request to your origin.
- A Lambda function can also make network calls to external resources to confirm user credentials, or fetch additional content to customize a response.