Search code examples
amazon-web-servicesamazon-s3amazon-cloudfrontaws-api-gateway

Cannot fetch static files from S3 via CloudFront CDN


I am trying to fetch GET a JSON static file which is in my public folder on cloudfront/S3. It works no problem on my local development environment where my files are stored locally, but on AWS I cannot fetch it; it returns my index html instead. Also if I paste the URL into my browser it takes me to the login, instead of displaying the json, like it does on my local environment. How do I retrieve the JSON static file?


Solution

  • The problem was the CloudFront setup I was using requires various cookies to be sent in every request in order to GET static content. These cookies were being saved in document.cookie but fetch does not include cookies by default, unless you pass the credentials: 'include' option.