CloudFront vs. Cloudflare: Two Ways to Connect AWS Origins
Choosing a CDN for an AWS origin: start with origin access boundaries, not the brand
If most of your website content is hosted on AWS and your team wants to keep origin access control, delivery configuration, and billing reconciliation within the AWS ecosystem, CloudFront usually deserves a place near the top of your evaluation list. If you already use Cloudflare to manage website ingress and want unified proxying, caching, and ingress rules without moving your AWS applications, Cloudflare can also be a reasonable choice. The prerequisites are controlled, verifiable access to the AWS origin and a budget that accounts for AWS charges generated by origin requests.
This is not a choice between “AWS-native is always faster” and “Cloudflare is always easier to set up.” For static files served from cache, the primary delivery path runs from the user to the edge. For login, payment, and API requests that cannot use a shared cache, the request must also travel from the edge to the AWS origin. These workloads have very different bottlenecks, costs, and acceptance criteria.
This article compares CloudFront distributions connected to AWS origins with Cloudflare website reverse proxying and caching connected to AWS origins. It does not treat Cloudflare R2, application migration to Workers, dedicated interconnections, or chaining the two CDNs as equivalent solutions, nor does it rank speed by node count. The available information is sufficient to explain integration mechanisms and billing boundaries, but it does not include real-world comparative measurements using the same AWS origin and the same user networks.
Two request paths: more than a DNS change
CloudFront: organizing origins and delivery rules around distributions
The central configuration object in CloudFront is the distribution: you define origins, delivery domains, and associated settings, then point your application domain to the delivery endpoint. AWS's CloudFront introduction explicitly lists origins such as S3 and HTTP servers, including HTTP servers running on EC2. You can use the distribution domain name or configure your own domain.
The logical path is:
User → Application domain DNS resolution → CloudFront → Configured AWS origin
When a usable cached response is available, the request does not need to retrieve the original content each time. An origin request path is used when content is missing from cache, requires revalidation, or is configured not to be cached. A “miss” indicated by a single edge response header is not enough to establish that the request reached your origin; confirm this against origin logs.
This approach supports incremental integration by application or resource domain. For example, you can migrate a static asset domain first, then handle pages and APIs. Using CloudFront does not require moving authoritative DNS management for the entire domain. What matters is that the existing DNS service can point correctly to the delivery endpoint and satisfy the relevant domain validation requirements.
Cloudflare: routing the website domain through a reverse proxy
Cloudflare's CDN product overview describes a reverse proxy model: users access the website domain, reach Cloudflare first, and Cloudflare then retrieves content from the origin. For an application on AWS, the logical path is:
User → Proxied application domain → Cloudflare → AWS origin endpoint
Distinguish between “DNS is managed by Cloudflare” and “requests pass through the Cloudflare proxy.” The existence of a DNS record does not mean application traffic necessarily passes through the CDN. Before switching production traffic, verify the record's proxy status, available setup modes, and actual account support. Seeing the domain in the DNS console alone does not mean integration is complete.
If the chosen setup mode requires changing authoritative DNS, the scope of the change may extend beyond the website. Mail records, domain verification records, and other subdomain records must all be migrated completely. If you want to retain your existing authoritative DNS, first confirm which setup options your account supports rather than assuming every plan offers the same choices.
Compare the complete solutions
Evaluation area | What to verify for CloudFront | What to verify for Cloudflare |
|---|---|---|
Delivery endpoint | Distribution, application domain association, certificates, and DNS target | Domain setup mode, proxy status, edge certificates, and scope of DNS changes |
AWS origin | Origin type, connection method, authorization, and network reachability | AWS endpoint reachability, origin TLS, origin identity, and access restrictions |
Cache governance | Cache and origin request requirements for each application path | Cache rules and exceptions for each application path |
Cost accounting | Edge data transfer out, requests, and related feature charges | Cloudflare service charges plus AWS charges such as origin data transfer out |
Troubleshooting | Correlating delivery logs with AWS origin logs | Correlating Cloudflare records with AWS origin logs |
This table does not rank product capabilities. Procurement should compare the configuration, services, and maintenance responsibilities required to achieve the same business objective—not two home-page feature lists.
S3 and application servers require different integration assumptions
Private S3: resolve object authorization before discussing caching
For static assets in S3, the first decision is not how long to cache them. It is whether the objects may be publicly readable and who is authorized to read them.
CloudFront's official documentation explicitly states that S3 content can be publicly readable or kept private with controlled access. However, the ability to deliver private content does not replace verification of the actual configuration. Origin authorization and viewer authorization are separate layers, and successfully opening a file through the application domain does not prove that the bucket remains private.
Likewise, pointing the Cloudflare proxy at an S3 endpoint does not mean it automatically inherits access authorization within AWS. You must specify how requests are authorized: through public objects, a restricted endpoint, or an explicitly designed signing mechanism or intermediary application layer. Whether a particular method is supported by the account and product requires separate verification. Do not make a previously private bucket public simply to complete CDN integration.
Acceptance testing should check at least three things:
Whether authorized access through the application domain succeeds and returns the correct content.
Whether objects that should not be public remain inaccessible when the intended delivery endpoint is bypassed.
Whether, after authorization expires or is revoked, the edge can still serve shared cached content to users who should no longer have access.
The third check is often overlooked. An access denial from the origin does not mean a copy already stored at the edge becomes invalid immediately. For paid files or private media, the location of access checks, cache policy, and revocation mechanism must be designed together.
Load balancers and EC2: network connectivity is only the first step
For application servers, a successful origin request involves at least the destination address, port, TLS certificate, HTTP Host, and application routing. Entering an AWS endpoint in the CDN console addresses only part of this.
Record these four values separately:
The application domain users access, such as
www.example.com.The name or address the CDN uses to locate the origin.
The SNI name used in the TLS handshake with the origin.
The Host sent in the HTTP request to the origin.
These values may be identical or different, but they must align with the certificate and the application's virtual host rules. Otherwise, TCP may connect while TLS validation fails, or TLS may succeed while the request reaches the wrong site. Do not attribute every failure to the “CDN's origin network path.”
The CloudFront product page lists VPC origin capabilities, but that does not mean any private AWS resource can be connected without conditions. If the origin must not be exposed to the public internet, first verify the applicable resource types, regions, network requirements, and account conditions. A Cloudflare solution likewise needs an explicit private connectivity or controlled-ingress design. A public DNS record is not a substitute for network isolation.
Origin restrictions must support recovery, not lock out legitimate access
If you restrict origin access by source address, request authentication, or application rules, tighten controls in stages: first record the characteristics of legitimate requests, then validate them through a test endpoint, and finally apply narrowly scoped restrictions to production paths.
Do not assume all CDN origin traffic comes from a small set of fixed addresses. Address range maintenance, health checks, certificate validation, and emergency access must all be included in the design. Secret values in request headers must not appear in public frontend code, sample code, or access logs. If you use this form of validation, define rotation procedures and a recovery plan for exposure.
Equivalent cache behavior matters more than which service returns 200 first
Classify application responses instead of guessing from file extensions
Cloudflare's cache documentation describes default caching behavior, Cache Rules, tiered caching, purging, and other capabilities. This does not mean all pages or APIs are cached automatically, nor does it mean every documented capability is enabled on your account.
When comparing CloudFront and Cloudflare, first write a vendor-neutral application policy, then implement it on each platform:
Request category | Recommended application policy | Risks that must be verified |
|---|---|---|
Content-fingerprinted JS, CSS, and images | Allow longer shared caching while content remains unchanged | Reference new files after releases and retain old files for a compatibility window |
Anonymous public pages | Share cached responses within a defined update interval | Whether language, region, or experiment cohorts change the content |
Login pages and account endpoints | Keep them out of public shared caches | Correct handling of cookies, authentication information, and response headers |
Public read-only APIs | Cache only responses confirmed to be shareable | Query parameters, tenants, permissions, and data freshness |
Upload, payment, and write endpoints | Avoid caching them as shareable objects | Request bodies, methods, timeouts, and retry semantics |
These are configuration objectives, not the default behavior of either product. Testing must reflect the rules actually in effect on the account.
Cache keys determine correctness as well as hit ratio
A cache key determines which requests can share the same response. If a product price varies by currency but currency is not included in the effective cache variation criteria, users may receive the wrong price. If every tracking parameter is included in the cache key, the same image may be fragmented into many objects with little reuse.
Also distinguish between “forwarded to the origin” and “included in the cache key.” A forwarded field does not necessarily affect how edge objects are distinguished. Conversely, including a field in the cache key does not prove that the origin received the information the application requires. Document both separately for each solution rather than relying on a screenshot showing “forward all headers.”
Use controlled requests to verify behavior: for the same resource, change irrelevant tracking parameters, application query parameters, language, and authentication state in sequence, then inspect response content, origin access records, and cache indicators. Test authentication states with isolated test accounts. Do not copy real cookies or tokens into shared terminal records.
If any request group receives another user's content, immediately stop shared caching for that path, correct the cache key or bypass rules, purge the affected objects, and retest. This is a release blocker; a higher hit ratio cannot compensate for it.
Purge testing must account for caches beyond the edge
Purging the edge does not clear copies in browsers, application-local caches, or other proxies. When a mutable file is updated in place, retrieving the new version in one check does not prove every user has received it.
Prefer content-fingerprinted versions for static assets. For pages and data that must be updated in place, record the purge scope, submission time, completion feedback, and the old or new versions observed at each sampling location. Start purge operations with a single test object. Do not repeatedly purge the entire site merely to compare speed.
Test error responses as well: make an isolated test resource return an error, restore normal operation, and observe whether the old error persists after recovery. Record the status code, response body identifier, and cache age to distinguish an origin that has not recovered from a cache that is prolonging the impact of an error.
Use commands to separate DNS, TLS, and origin request issues
Record a real GET request before calculating phase durations
The following command is suitable for checking a public test object. Replace the example path with a non-sensitive file you have deployed:
curl -sS -D edge-headers.txt -o /dev/null \
--connect-timeout 5 --max-time 20 \
-w 'code=%{http_code}\nip=%{remote_ip}\ndns=%{time_namelookup}\nconnect=%{time_connect}\ntls=%{time_appconnect}\nfirst_byte=%{time_starttransfer}\ntotal=%{time_total}\n' \
'https://www.example.com/assets/probe.txt'
Response headers are saved to a local file, and timing results are printed to the terminal. GET is used rather than HEAD alone to more closely reflect actual object retrieval. A successful HEAD request does not prove that the GET response body, caching, and download path work correctly. Check the response header file for sensitive information before sharing it.
These timings are cumulative from the start of the request, so time_appconnect cannot be described directly as the TLS phase duration. For a single request over a new HTTPS connection with no redirects, approximate phase durations can be calculated as follows:
DNS phase:
time_namelookup.TCP phase:
time_connect - time_namelookup.TLS phase:
time_appconnect - time_connect.TLS completion to first byte:
time_starttransfer - time_appconnect.Receive time after the first byte:
time_total - time_starttransfer.
These differences are not an exact breakdown that applies to every protocol scenario. Connection reuse, HTTP versions, and proxies affect their interpretation. The command does not automatically follow redirects. If it returns 3xx, inspect the destination first, then record the redirect chain separately from the final resource so that redirect overhead is not mistaken for CDN processing time.
Use --resolve to preserve Host and SNI when verifying the origin
If you have authorization, the origin directly accepts the application domain, and the certificate matches, run the following from an approved test egress point:
curl -sS --resolve www.example.com:443:203.0.113.10 \
--connect-timeout 5 --max-time 20 \
-D origin-headers.txt -o /dev/null \
-w 'code=%{http_code}\nfirst_byte=%{time_starttransfer}\ntotal=%{time_total}\n' \
'https://www.example.com/assets/probe.txt'
203.0.113.10 is a documentation example address. Replace it in a controlled environment when running the command, and do not disclose the real origin address publicly. This method preserves the Host and TLS SNI from the URL, making it more suitable for virtual host verification than requesting an HTTPS IP address directly and adding a Host header.
If the CDN actually uses a different origin SNI or Host, this command does not reproduce the real origin request. Create a separate test that follows the intended design. It also measures only the path from the test egress point to the origin, not network quality between the CloudFront or Cloudflare edge and the origin.
Handle the results as follows:
Both origin and edge requests fail: Check the object, application, certificate, and origin permissions before investigating CDN differences.
The origin succeeds but the edge fails: Check the CDN's origin name, Host, TLS validation, access restrictions, and edge rules.
The edge succeeds but direct origin access is denied: This may be the intended isolation behavior. Check the denial rules rather than immediately relaxing protection.
Both succeed but return different content: Compare object versions, cache keys, compression, and response rewriting—not just status codes.
Do not “fix” the test by disabling certificate validation. A certificate error is itself an integration issue that needs to be resolved.
Performance comparisons must separate cache hits from dynamic requests
Using the same AWS origin is necessary but not sufficient. A controlled comparison also requires the same object version, size, request method, request headers, response compression, and cache policy. If you use two test domains, confirm that different Host values do not cause the origin to return different content, redirects, or cookie scopes.
Where feasible, configure both services with valid settings and certificates for the same application domain, then select different endpoints from an isolated test environment while keeping Host unchanged. Verify whether the specific endpoints support this testing method. Do not arbitrarily select a resolved IP address and treat the result as representative of the provider's overall performance.
Choose observations by request type
For small static files, focus on success rate, time to first byte, and whether all resources required by the page are available. For large files, also measure download completion, throughput, and interruptions. For video, distinguish manifests from segments and observe startup time, recovery after seeking, and playback stalls. A small file's TTFB cannot predict the video experience.
For dynamic APIs, examine application-level status, end-to-end latency, origin processing time, and write correctness. If origin logs show that application processing accounts for most of the time, changing CDNs may not solve the problem. If both services serve cache hits quickly but differ substantially on uncacheable requests, further investigation of origin connections and cross-region paths is warranted.
At a minimum, separate naturally cold-cache requests, steady cache hits, revalidation, and explicitly uncacheable requests. Adding a random query parameter does not necessarily create a cold-cache request because the parameter may not be part of the cache key. A more reliable approach is to use a dedicated new object and confirm its first retrieval in the origin logs.
Keep user regions and statistical methods consistent
Group samples by target country or region, ISP, residential broadband or mobile network, and IPv4 or IPv6. Analyze mainland China, Hong Kong/Macao/Taiwan, and overseas samples separately. Cloud server egress represents only the corresponding cloud network and cannot substitute for residential users.
For every group, record successes, failures, and timeouts, and report sample size, typical latency, tail latency, and error types. Do not compare only the fastest successful request, and do not simply average regional P95 values into an overall P95. Observed platform success rate and contractual SLA are different metrics.
You can start with CdnChart's provider comparison to organize evaluation criteria, then use its measurement methodology and evidence standards to define your sampling plan. Page observations, response headers, and IP ownership are supporting evidence only; they cannot reconstruct the complete origin request network.
Cost differences: how AWS-to-edge traffic is billed
CloudFront's official integration documentation states that data transfer from the listed AWS origins to CloudFront is not charged for that transfer segment. Delivery from the edge to viewers is billed across dimensions such as data transfer out and requests. This must not be interpreted as meaning the entire AWS application has no other costs. S3 requests, application compute, logs, and related services still need to be included.
The Cloudflare solution cannot automatically use the same billing boundary. Whether AWS charges for transferring content to Cloudflare must be confirmed for the specific AWS service, origin region, applicable contract, and discount terms. Cloudflare's bandwidth descriptions do not automatically offset the AWS bill.
Use the same currency, billing period, and traffic units, then model each solution separately:
Total cost = CDN delivery charges + AWS origin-related charges + Optional feature charges + Logging and operations costs
For CloudFront, the pricing worksheet should include viewer locations, delivered bytes, HTTP/HTTPS request volume, and enabled security, compute, logging, and other services. For Cloudflare, confirm the scope of website services, caching and security features, logs, support, and contractual constraints. List AWS origin data transfer out, requests, and application processing charges separately. Do not mix GB with GiB, or request counts with peak bandwidth.
Use byte hit ratio for the origin traffic budget
A high request hit ratio does not necessarily mean low AWS data transfer out. If many small icons are cache hits while a few large downloads miss, the request hit ratio may look excellent even though the origin byte volume remains high.
For static workloads dominated by complete-object delivery, with relatively little retry and revalidation overhead, the following formula provides an initial estimate:
Bytes fetched from the origin ≈ Bytes delivered × (1 - Byte hit ratio)
This is not a billing formula. Range requests, retries, object updates, compression differences, and multiple cache layers can all cause deviations. Reconcile the result against origin metering, delivery logs, and bills rather than multiplying the number of edge MISS events by an average file size.
Tiered caching may reduce repeated origin fetches from multiple edges, but whether it is enabled, how it is billed, and how much it actually reduces origin traffic all require separate verification. Tiered Cache and Cache Reserve in Cloudflare's documentation are different capabilities. Do not assume they provide the same effect as an inherent part of basic proxying.
For highly reusable static assets, a Cloudflare solution that substantially reduces bytes fetched from AWS may change the total cost. For dynamic traffic that is almost entirely uncacheable, cache savings cannot justify the purchase. In that case, origin data transfer out and application processing costs must be modeled against real request volumes.
From validation to production: turn evidence into adoption criteria
When to evaluate CloudFront first
If your content and applications are primarily on AWS, especially where private objects, origin isolation, and centralized billing reconciliation are required, evaluate CloudFront first. This assessment rests on integration alignment and the officially documented AWS origin transfer boundary—not a guarantee of performance in every region.
The adoption criteria are that the existing origin can be connected under the intended network and authorization model; caching and access control meet application requirements; and tail latency, failure rate, and cost for the main user networks meet the team's predefined targets. If these conditions are not met, identify the specific causes before considering an alternative endpoint. Do not insist on CloudFront solely because the origin is on AWS.
When Cloudflare is worth evaluating
If your team already manages website ingress through Cloudflare, AWS is only one of its backend hosting environments, and you want consistent proxy and rule governance, Cloudflare deserves a like-for-like trial. This path is particularly straightforward to model when static content is shareable, update policies are clear, and AWS origin traffic costs are manageable.
The adoption criteria are that the impact of DNS changes is controlled, origin TLS and identity verification are clearly defined, uncacheable requests still meet experience requirements, and AWS-side costs have not been overlooked. If integration requires directly exposing a private origin to the internet, or critical logs cannot support troubleshooting, address the architecture first rather than rushing the traffic switch. The selection guide can help organize candidate constraints, but account configuration and application validation must determine the final decision.
Prepare staged rollout and rollback before changing DNS
First establish an isolated test endpoint and verify certificates, Host/SNI, caching, redirects, and security rules. Then roll out low-risk assets or a limited part of the application. If switching through DNS, adjust TTL in advance and allow existing cached records to age out naturally. Lowering TTL does not guarantee that every client refreshes immediately.
The observation window should cover peak traffic, an asset release, and at least one content update. Define rollback triggers before launch: cross-user content exposure, increased errors on critical endpoints, worsening timeouts on target networks, abnormal origin load, or AWS origin traffic exceeding budget assumptions. Security correctness issues require stopping the affected path first, not waiting for statistical significance.
Keep the old endpoint, certificates, and necessary origin permissions until the rollback window closes. Restoring DNS does not clear responses that were cached incorrectly. If the incident involves cache poisoning, also disable the relevant rules, purge affected objects, and assess the impact of browser caches. Origin access restrictions must allow both legitimate paths during migration and be tightened only after the system is stable. Do not close the old path first and then expect a seamless rollback.
The solution worth adopting is not the provider that wins a single speed test. It is the one that can demonstrate four things at once: authorized requests receive the correct content, unauthorized requests cannot bypass access boundaries, real user networks meet the intended experience targets, and the complete bill fits the budget. Apply the same criteria to CloudFront and Cloudflare. If any critical condition cannot be demonstrated, continue limited testing or retain the existing delivery path rather than using the production traffic switch as a test.
- CloudFront vs. Cloudflare
- AWS origin CDN integration comparison
- CDN cache keys and origin requests
- AWS origin data transfer out costs