This guide uses AWS CloudFront as a CDN/proxy layer with Route53 for DNS. This approach is ideal if you’re already running infrastructure on AWS.
Prerequisites
- An AWS account with access to CloudFront and Route53
- A domain with DNS managed by Route53 (or ability to point external DNS to CloudFront)
- Basic familiarity with AWS console
Architecture Overview
/analytics/* to Composite’s API while your main site continues to work normally.
Setup Guide
Create a CloudFront distribution
- Open the CloudFront console
- Click Create distribution
- Configure the origin:
- Origin domain:
prod.alb.us.api.composite.com - Protocol: HTTPS only
- HTTPS port: 443
- Name:
composite-analytics-origin
- Origin domain:
- Under Default cache behavior:
- Viewer protocol policy: Redirect HTTP to HTTPS
- Allowed HTTP methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE
- Cache policy: CachingDisabled
- Origin request policy: AllViewerExceptHostHeader
- Click Create distribution
Add a behavior for /analytics path
After the distribution is created:
- Go to the Behaviors tab
- Click Create behavior
- Configure:
- Path pattern:
/analytics/* - Origin: Select your
composite-analytics-origin - Viewer protocol policy: Redirect HTTP to HTTPS
- Allowed HTTP methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE
- Cache policy: CachingDisabled
- Origin request policy: AllViewerExceptHostHeader
- Path pattern:
- Click Create behavior
Configure Route53 DNS
- Open Route53 console
- Go to Hosted zones → Select your domain
- Click Create record
- Configure:
- Record name: Leave empty for root domain
- Record type: A
- Alias: Yes
- Route traffic to: Alias to CloudFront distribution
- Choose distribution: Select your distribution
- Click Create records
DNS propagation typically takes a few minutes but can take up to 48 hours in rare cases.
Test Your Distribution
Before configuring your SDK, verify CloudFront is routing requests correctly:-
Find your CloudFront distribution domain in the General tab (e.g.,
d1234abcd.cloudfront.net) -
Test the analytics endpoint:
- You should see a response from the Composite API
Troubleshooting
CloudFront returns 502 Bad Gateway
CloudFront returns 502 Bad Gateway
This usually means CloudFront cannot reach the origin:
- Verify the origin domain is correct:
prod.alb.us.api.composite.com - Ensure HTTPS is enabled on the origin settings
- Check that the origin request policy is
AllViewerExceptHostHeader
Requests return 404
Requests return 404
Check your CloudFront behavior configuration:
- Verify the path pattern is
/analytics/* - Ensure the origin is set to
prod.alb.us.api.composite.com - Check that the behavior is using the correct origin
CORS errors in extension
CORS errors in extension
CloudFront should pass through CORS headers from the origin. If you’re still seeing errors:
- Create a CloudFront response headers policy with CORS settings
- Attach it to your
/analytics/*behavior