Amazon CloudFront is the AWS content delivery network (CDN) service. It speeds up the delivery of static and dynamic web content, such as .html, .css, .js, and image files, to your users. CloudFront delivers content through a worldwide network of data centers called edge locations (points of presence, or POPs). When a user requests content, CloudFront routes the request to the edge location with the lowest latency:
Requests travel over the AWS backbone network instead of the public internet, which lowers latency and raises transfer rates. Because copies of your objects are cached in many edge locations, your application also gains reliability and availability. By default, an object stays in an edge cache for 24 hours, and you can change this with cache headers or cache policies.

In this workshop you configure the following CloudFront features:
EC2 and S3 origins: An origin stores the definitive version of your content. You will use an S3 bucket and a web server on an EC2 instance (a custom origin) as origins. For S3 origins, AWS recommends origin access control (OAC) so that the bucket stays private and only CloudFront can read it.
CloudFront distribution: A distribution tells CloudFront which origins to fetch content from and how to cache and deliver it. CloudFront assigns it a domain name such as d111111abcdef8.cloudfront.net, and you can add your own alternate domain name. CloudFront offers standard distributions for a single website or application, and multi-tenant distributions (CloudFront SaaS Manager) for SaaS providers that serve many similar customer sites. This workshop uses a standard distribution.
Invalidations: Remove objects from edge caches before they expire so viewers get the latest version from the origin.
Custom error pages: Return your own error page, and optionally a different HTTP status code, when the origin returns an error.
Origin groups (origin failover): An origin group contains a primary and a secondary origin. When the primary origin returns an HTTP status code that you configured for failover, or the connection fails or times out, CloudFront sends the request to the secondary origin. Failover applies to GET, HEAD, and OPTIONS requests.
Response headers policies: Add or remove HTTP headers in the responses CloudFront sends to viewers, for example security headers, CORS headers, or custom headers.
Cache behaviors: A cache behavior maps a URL path pattern (for example, all paths under /images/) to an origin and to settings such as the cache policy, origin request policy, allowed HTTP methods, and edge functions. You will create an additional cache behavior alongside the default one.
Create a Lambda@Edge function: Lambda@Edge runs Node.js or Python code in response to four CloudFront events: viewer request, viewer response, origin request, and origin response. Use it for logic that needs network access, third-party libraries, the request body, or more memory and run time. For lightweight work such as header changes, URL rewrites, or token validation on viewer events, CloudFront Functions (JavaScript, sub-millisecond, millions of requests per second) is usually the cheaper option.
Deploy Lambda@Edge to CloudFront: Publish a numbered version of the function (created in the US East (N. Virginia) Region) and associate it with a cache behavior event. CloudFront then replicates it to locations around the world.
Metrics and logs: CloudFront publishes metrics to Amazon CloudWatch and provides several kinds of logs:
With pay-as-you-go pricing, CloudFront charges for data transfer out from edge locations and for HTTP/HTTPS requests. Data transfer from AWS origins such as Amazon S3, Elastic Load Balancing, or Amazon API Gateway to CloudFront is free. CloudFront also offers flat-rate pricing plans (Free, Pro, Business, and Premium) that bundle the CDN with AWS WAF and DDoS protection, bot management, Amazon Route 53 DNS, CloudWatch Logs ingestion, a TLS certificate, serverless edge compute, and monthly S3 storage credits for a fixed monthly price with no overage charges. See CloudFront pricing for current rates.
The EC2 instance, S3 storage, real-time logs (Kinesis Data Streams), and log delivery all keep billing after the lab. Complete the cleanup section when you finish. Lambda@Edge replicas can take a few hours to delete after you remove the association, so the function may not be deletable right away.
By the end of this workshop, you will have a CloudFront distribution with EC2 and S3 origins, failover, custom error handling, response headers, multiple cache behaviors, and a Lambda@Edge function, along with the metrics and logs to monitor it.