Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Amazon CloudFront and Lambda@Edge

Ric Harvey, AWS Solutions Architect

  • Be the first to comment

Amazon CloudFront and Lambda@Edge

  1. 1. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. @ric__harvey rjh@amazon.com Amazon CloudFront + Lambda@Edge Ric Harvey, Technical Developer Evangelist
  2. 2. Content Delivery Network
  3. 3. § Accelerate static and dynamic § Protect origin servers from load § Global Infrastructure § Highly Secure § Massively Scalable § Self Service § Priced to Minimize Cost CloudFront: Global Content Delivery Network
  4. 4. Amazon CloudFront Global Content Delivery Network 113 PoPs (102 Edge Locations + 11 Regional Edge Caches) Edge Locations Multiple Edge Locations Regional Caches
  5. 5. Customers across many industries Social Media, Digital Advertising, EdTech, Finance Enterprise E-commerce Media & Entertainment Gaming
  6. 6. Why are CDN’s important?
  7. 7. Bring your own…… Amazon Route 53 allows you to bring your own alias’s to a Cloudfront distribution
  8. 8. AWS Certificate Manager (ACM) makes it easy to provision, manage, deploy, and renew SSL/TLS certificates on the AWS platform. Bring your own……
  9. 9. Serverless
  10. 10. No servers to provision or manage Scales with usage Never pay for idle Built-in availability and fault tolerance Serverless means …
  11. 11. How it works Event source Services (anything) Changes in data state Requests to endpoints Changes in resource state Function
  12. 12. …but what if you could run your Lambda functions at multiple locations closer to the viewer?
  13. 13. Amazon CloudFrontAWS Lambda Lambda@Edge Lambda@Edge
  14. 14. Globally distributed Scales with usage Never pay for idle Built-in availability and fault tolerance Bring your own code to the edge to improve user experience Lambda@Edge No servers to provision or manage
  15. 15. Write once, run Lambda functions globally N Virginia AWS Location AWS Location AWS Location AWS Location AWS Location AWS Location
  16. 16. Lambda@Edge Origin AWS Location AWS Location AWS Location AWS Location AWS Location AWS Location Compute Storage Database
  17. 17. Lambda@Edge Content-based routing to any origin Response generation • Generate custom responses at the edge • Read and write access to headers, query string, and cookies Network calls • Origin events • Viewer events
  18. 18. Lambda vs Lambda@Edge Lambda Lambda@Edge Languages Node.js, Python, C#, Java Node.js Memory 128->1536MB 128MB Execution time <300 seconds <3 seconds (Origin-facing) <1 seconds (Viewer-facing) Deployment size <50MB <1MB Request pricing First 1 million free $0.20 per 1 million $0.60 per 1 million Duration granularity 100ms 50ms 128MB for 100ms $0.000000208 $0.000000625
  19. 19. Use cases
  20. 20. Usecases – Response generation Multiple origins Personalisation (e.g. ‘Ric’s Account’ in the top-left) Results of multiple API calls Content-type transformation (e.g. XML->JSON)
  21. 21. Usecases – HTTP Redirects Cool URIs don’t change (…though they may redirect) Redirect to latest version Redirect example.com -> www.example.com
  22. 22. Usecases – URL Rewriting Semantic (pretty) URLs /foo-cms/view/42.asp -> /articles/42 Adaptive content Client capabilities – Accept-Type header, screen size Image cropping/resizing
  23. 23. Usecases – Security Best Practices Add security response headers: • Strict-Transport-Security • Content-Security-Policy • X-Content-Type-Options • X-Frame-Options • X-XSS-Protection • Referrer-Policy • Public-Key-Pins Remove informational response headers: • Server • Powered-By
  24. 24. Usecases –Authorization Bot handling – using CAPTCHA Non-standard authorization (not HTTP Basic/Digest/etc) Origin doesn’t implement authorization Pay-per-view / Paywall application
  25. 25. Usecases – A/B Testing Test your theory on a proportion of users Measure valuable metric (social likes/shares, engagement, purchases, etc) Implement findings
  26. 26. Usecases: Origin request, Origin selection id user 1 alex 2 bob 3 joe 4 jane User database 200 OK Application User Agent POST /login user=jane&pass=*** home-region na eu ap eu Set-Cookie: home-region=eu
  27. 27. User Agent CloudFront distribution www.example.com North America origin User DB Cache Behavior /login North America app DB hom e-region=na ? Europe origin Europe app DB home-region=eu ? APAC origin APAC app DB home-region=ap ? Cache Behavior /app Origin Request Event Set-Cookie Usecases: Origin request, Origin selection
  28. 28. Summary
  29. 29. CloudFront CDN’s are good! • They protect origins from load • Accelerate static and dynamic content (websites, APIs) • Scalable and Global • Cache content closer to the user • Support HTTP/2 and IPv6
  30. 30. Summary Lambda@Edge Features: Header manipulation URL rewrites Response generation Benefits: Bring your own code Familiar programming model Write once, run everywhere
  31. 31. Ric Harvey, Technical Developer Evangelist @ric__harvey rjh@amazon.com

×