2019, Amazon Web Services, Inc. or its Affiliates. Corneliu Croitoru – Solutions Architect AWS Rendering websites at the edge with Lambda@Edge October 17th 2019
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.
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
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
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
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
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
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
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
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>
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
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
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