Proxy requests to Experiment with AWS Cloudfront
Set up a reverse proxy to circumvent domain blocking in particular regions or by certain extensions and DNS servers. Because experiment APIs are latency sensitive, Amplitude recommends an edge-hosted solution to minimize round-trip time from the proxy to Amplitude.
Create a distribution
Follow these steps to create a new CloudFront distribution that proxies requests to Amplitude Experiment's evaluation servers. Leave any configuration field not mentioned in the steps at its default value.
- In AWS, go to CloudFront and select Create distribution.
- In the Origin domain field, enter
api.lab.amplitude.comfor the US data center orapi.lab.eu.amplitude.comfor the EU data center. - In the Default cache behavior section, select
GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETEfor Allowed HTTP methods andOPTIONSfor Cache HTTP methods. The Cache HTTP methods field appears after you select an Allowed HTTP methods value. - In the Cache key and origin requests section, select the
CachingDisabledcache policy, theAllViewExceptHostHeaderorigin request policy, and theCORS-with-preflight-and-SecurityHeadersPolicyresponse headers policy. These selections require that you choose Cache policy and origin request policy (recommended) rather than Legacy cache settings. - In the Web Application Firewall (WAF) section, select Do not enable security protections.
- Select Create distribution.
Test the distribution
Test the new distribution with a curl request. To find the distribution domain name, select the new distribution from the list in CloudFront and copy the subdomain. Replace SUBDOMAIN in the following command with that subdomain. Replace APIKEY with your deployment or project API key to authorize the request.
Successful requests return a 200 response.
curl -i 'https://SUBDOMAIN.cloudfront.net/v1/vardata' -H 'Authorization: Api-Key APIKEY'
Was this helpful?