15

I have created an S3 and I uploaded files on the bucket successfully. Now, I am trying to make it work with CloudFront however it is giving me

IllegalLocationConstraintException

The ap-east-1 location constraint is incompatible for the region specific endpoint this request was sent to.

My S3 url is: http://my-bucket-name.s3.ap-east-1.amazonaws.com/assets/local/css/app.css (this returns me the file)

CloudFront is linked to the S3, and the url: https://id.cloudfront.net/assets/local/css/app.css (this returns me the IllegalLocationConstraintException)


In S3 bucket > Permissions >

"Block Public Access" is Off

"Bucket Policy" is auto-generated:

{
    "Version": "2008-10-17",
    "Id": "PolicyForCloudFrontPrivateContent",
    "Statement": [
        {
            "Sid": "1",
            "Effect": "Allow",
            "Principal": {
                "AWS": "######"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-bucket-name/*"
        }
    ]
}

What am I doing wrong?

2 Answers 2

32

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

5
  • 3
    Amazon UI will give you a broken name in a dropdown without the region in it. Looks like the naming convention was different for me. Got my Cloudfront distribution to serve s3 bucket content by setting the origin domain name to: bucketname.s3-website.region.amazonaws.com which is actually just the s3 website domain you can browse directly
    – Caz
    May 8, 2020 at 19:21
  • 5
    Worked perfectly for me for the Milan region. You probably saved me hours of desperation. Jun 17, 2020 at 3:41
  • 2
    @IvanCarosati same here. I don't get the reason why once selected the s3 bucket is not correctly specified depending on the region.
    – Masiorama
    Mar 17, 2021 at 14:30
  • 1
    Fixed my issue for Hong Kong S3 bucket as well. I caught it through this thread as well as an AWS youtube video no less, from 2018 mentioning the same trick - copy the S3 path from S3 console and paste into the origin field. Has this been an issue for 3+ years?
    – chopper24
    Mar 21, 2021 at 16:46
  • 1
    This surely I hope is flagged as a bug with AWS. Strange indeed. Apr 27, 2021 at 18:13
13
  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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.