Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rendering Websites at the edge with lambda@Edge

Marc
October 17, 2019

Rendering Websites at the edge with lambda@Edge

Rendering websites at the edge with Lambda@Edge
Presentation : Corneliu Croitoru

Marc

October 17, 2019
Tweet

More Decks by Marc

Other Decks in Technology

Transcript

  1. © 2019, Amazon Web Services, Inc. or its Affiliates. ©

    2019, Amazon Web Services, Inc. or its Affiliates. Corneliu Croitoru – Solutions Architect AWS Rendering websites at the edge with Lambda@Edge October 17th 2019
  2. © 2019, Amazon Web Services, Inc. or its Affiliates. What

    to expect Brief presentation (~15min) • Global serverless computing with Lambda@Edge • Overview of the workshop labs Time to build! (~90min) Workshop cost? Less than $0.5. Free tier applies.
  3. © 2019, Amazon Web Services, Inc. or its Affiliates. Launch

    the AWS CloudFormation stack https://github.com/aws-samples/aws-lambda-edge-workshops Google: aws lambda edge workshop
  4. © 2019, Amazon Web Services, Inc. or its Affiliates. AWS

    Locations: Where is Your Customer? 189 Points of Presence 73 cities 33 countries 22 AWS Regions
  5. © 2019, Amazon Web Services, Inc. or its Affiliates. Origin

    AWS Locations: Where is Your Customer?
  6. © 2019, Amazon Web Services, Inc. or its Affiliates. AWS

    Lambda: Why Serverless? Build and run applications without managing servers No servers to manage Run at scale Respond quickly to events Only pay for compute time that you use Developer productivity
  7. © 2019, Amazon Web Services, Inc. or its Affiliates. Amazon

    CloudFront: Global Content Delivery Global, growing content delivery network High performance—speed up distribution of your static and dynamic web content to your users across the world DDoS resiliency, scale, and cost effective Flexible and highly “programmable” with AWS Lambda@Edge
  8. © 2019, Amazon Web Services, Inc. or its Affiliates. Global

    Serverless: Run Lambda Functions Across AWS Locations
  9. © 2019, Amazon Web Services, Inc. or its Affiliates. Benefits

    of AWS Lambda@Edge Continuous scaling No servers to manage Never pay for idle Global presence
  10. © 2019, Amazon Web Services, Inc. or its Affiliates. Amazon

    CloudFront and Lambda@Edge CloudFront cache Origin response Origin Viewer Origin request Viewer response Viewer request
  11. © 2019, Amazon Web Services, Inc. or its Affiliates. Lambda@Edge

    use cases Simple HTTP manipulations Dynamic content generation Origin independence User-agent header normalization Image manipulation Pretty URLs Adding HSTS security headers Render pages API wrapper Enforcing cache-control headers Redirections Authorization A/B testing SEO optimization Bot mitigation
  12. © 2019, Amazon Web Services, Inc. or its Affiliates. Lambda@Edge

    vs Lambda Lambda@edge Lambda Runtime NodeJs Python NodeJs Python Java Go Bring your own runtime Memory 128 MB viewer event 3 GB origin event 128 MB to 3,008 MB (in 64 MB increments) Billing 50ms 100ms Trigger - Numbered version only in CloudFront - Numbered version - Alias from many services Pricing 1M requests FREE $0.60 per 1M requests 1M requests FREE $0.20 per 1M requests
  13. © 2019, Amazon Web Services, Inc. or its Affiliates. How

    much does it cost? Consider an API with 15M requests/month & 128MB Lambda@Edge function executing in two milliseconds. Viewer request event is configured on CloudFront. Lambda@Edge is charged based on • Number of requests: 15M*$.6/1M = $9 • Memory*Duration resource usage: 15M * 50ms * 128MB * $0.00005001/GBS = $4.7 Total cost is $13.7/month
  14. © 2019, Amazon Web Services, Inc. or its Affiliates. Serving

    Dynamic Content Services Mobile client Client Internet AWS Cloud Amazon CloudFront Amazon API Gateway AWS Lambda Amazon EC2 Elastic Load Balancing Generic group Amazon Elastic Container Service Amazon DynamoDB API Layer Application Layer Persistency Layer AWS S3
  15. © 2019, Amazon Web Services, Inc. or its Affiliates. Serving

    Dynamic Content at the Edge Services Mobile client Client Internet AWS Cloud AWS Lambda@Edge Amazon DynamoDB Global tables API Layer Application Layer Persistency Layer Amazon CloudFront AWS S3
  16. © 2019, Amazon Web Services, Inc. or its Affiliates. Alien

    Connect — the Serverless Stack AWS Lambda@Edge Amazon S3 Amazon DynamoDB Amazon CloudFront
  17. © 2019, Amazon Web Services, Inc. or its Affiliates. #1

    Enhance Security: Secure your Alien Cards Objective: let's check and improve your website security by configuring HTTP to HTTPs redirect and adding a number of standard security headers to enforce HTTPS connection is always used and prevent XSS. https://observatory.mozilla.org Security Headers: • Strict-Transport-Security • Content-Security-Policy • X-XSS-Protection • X-Content-Type-Options • X-Frame-Options
  18. © 2019, Amazon Web Services, Inc. or its Affiliates. #2

    Generate Content: View your Alien Cards, and Homepage Objective: in this lab, you will enhance the look and feel of your web-site by using Lambda@Edge function that dynamically generates HTML content that can be cached by CloudFront and returned back to your viewers Alien Card Details Homepage
  19. © 2019, Amazon Web Services, Inc. or its Affiliates. #3

    Simple API: Like Your Alien Cards Objective: in this lab, you will enhance the look and feel of your web-site by using Lambda@Edge function that dynamically generates HTML content that can be cached by CloudFront and returned back to your viewers POST /api/like?id=<card_id>
  20. © 2019, Amazon Web Services, Inc. or its Affiliates. #4

    Pretty URL: Share Your Alien Cards Objective: Objective: Make your URLs easy to remember and share Before: https://d3rugkzdgfe4op.cloudfront.net/card/da8398f4 After: https://d3rugkzdgfe4op.cloudfront.net/tree
  21. © 2019, Amazon Web Services, Inc. or its Affiliates. #5

    Optimize Content: Optimize your Alien Homepage for the device type Objective: Optimize look and feel depending on the viewer device type Desktop Device Mobile Device
  22. © 2019, Amazon Web Services, Inc. or its Affiliates. Alien

    Connect — Time to Build! • Launch CloudFormation stack • Raise a hand if you have a question or need help • LinkedIn Share/Tweet as you build – #LambdaEdge #StationF #aws https://github.com/aws-samples/aws-lambda-edge-workshops