DEV Community

Cao Duy Khanh
Cao Duy Khanh

Posted on

How to resolve issue Access Denied between S3 and CloudFront

I have setup S3 to store image files and access them through CloudFront. But I have an error Access Denied and link CloudFront was redirect to S3 link as below image:
Alt Text


The root cause of issue relates to “Requests made with the legacy global endpoint go to US East (N. Virginia) by default.”

Refer: https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html


To fix this issue, we need to back to setup CloudFront before.
Alt Text
Normally, we will select own s3 bucket which contains static files on dropdown list. In this case, endpoint is format as:<bucket>.s3.amazonaws.com
This endpoint is global endpoint. We need to change to region endpoint then issue will be fixed. The region endpoint format as: <bucket>.s3-<region>.amazonaws.com
Alt Text
The result as below
Alt Text

Top comments (8)

Collapse
 
osinachiuro profile image
Osinachi • Edited

Hi Cao,
I received the message below after i updated the region to us-east-1 and reloaded the page. Any ideas?

Collapse
 
khanhcd92 profile image
Cao Duy Khanh

Hi Osinachi-Uro,

Could you give me message or photo about your issue ?

Collapse
 
osinachiuro profile image
Osinachi

It returns a page that says:

ERROR
Failed to contact the origin

Collapse
 
osinachiuro profile image
Osinachi

It worked now!
It took a while but it's working fine now.
Thanks

Collapse
 
kevin_raymond_a7fd24aa704 profile image
kevin raymond

hey, im still unable to access the bucket objects even after specifying the region. Where did i go wrong?

Collapse
 
khanhcd92 profile image
Cao Duy Khanh

Could you share buck policy and config CloudFront for me ?

Collapse
 
kevin_raymond_a7fd24aa704 profile image
kevin raymond

hey Cao, i fixed it. Thanks though!

Collapse
 
jandiralceu profile image
Jandir Alceu

Thanks! It works for me! The origin domain, is the same generated when you create the static website hosting. In my case was: my-folder-name.s3-website-us-west-2.amazonaws.com