IllegalLocationConstraintException on CloudFront (for S3)

Even when you auto-select the S3 in CloudFront as related bucket, you still need to put your location manually for making it work.


Update:

My issue was because my CloudFront origin was not in us-east, and when you auto-select your bucket's origin in CloudFront, it doesn't add the location prefix to the url. So make sure you add your s3 location like so:

bucketname.s3.ap-east-1.amazonaws.com


  1. Go to your CloudFront dashboard and click on the distribution ID
  2. Go to 'Origins and Origin Groups' tab
  3. select your origin and click 'edit
  4. edit 'Origin Domain Name' to match this format bucketname.s3.regioncode.amazonaws.com
  5. save and wait for 'deployed' state