Ref: https://learn.cantrill.io/courses/1820301/lectures/41301532
CF Lambda at Edge (Lambda@Edge)
- 🔧 Run lightweight Lambda functions at CF edge locations
- Can adjust data between viewer & origin
- 💡 Because Lambdas run at edge locations, can't have full feature set of Lambda
- Limitations:
- Currently only supports Node.js and Python RTEs
- Runs in AWS public space → No access to VPC resources
- Lambda Layers NOT supported
- Stricter size & execution limits compared to normal Lambda functions
- Use cases
- A/B testing → viewer request Lambda
- Present two different versions of an image depending on viewer without redirects or changing URL from viewer's perspective → test two different versions of a webapp
- Migration between S3 origins → origin request Lambda
- Gradually transfer traffic from old S3 origin to new S3 origin
- Content by device → origin request Lambda
- e.g. Display higher resolution images for high DPI (dots per inch) devices
- Content by country → origin request Lambda
- Adjusts content based on country (or language)
- More examples (including Lambda code): https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-examples.html#lambda-examples-redirecting-examples
Lambda@Edge - Architecture

- Lambda can be triggered after traffic reaches CF and/or before traffic leaves CF
- e.g. Viewer Request Lambda: CF receives request from viewer, then triggers function
- 💡 No need to memorize the size & execution limits for Lambda@Edge, but understand that they are much stricter than normal Lambda & hence can only support certain use cases