Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 custom error document for access denied

I been trying to find a way to make it so when a user tries to "hotlink" or view content outside of viewing it directly through a page on my site which references S3 content that they will be served a generic image in the root of my bucket instead of the below XML browser output

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>6C57766666DF18C</RequestId>
<HostId>
bkreFGYkuilWBwa2xs3S35+CqofLB4ay1gD4UAEtmGJEaqE9tHvUZrsJO7i2JRw
</HostId>
</Error>

Any help or points in the right direction greatly appreciated

I already have a policy that restricts the content to only showing within my domain, just need the show a custom image part

like image 405
William Worley Avatar asked Sep 29 '22 08:09

William Worley


2 Answers

Additionally the following information is good to know.

Create your bucket, inside of that bucket upload 2 files index.html and error.html, then set these both to public.

In your settings for this bucket go to Static Web Hosting and in for Index Document enter index.html and for Error Document enter error.html, now you can try to access wrong documents and get the error.html file.

like image 102
William Worley Avatar answered Oct 17 '22 06:10

William Worley


Put your custome image in the document explained here

Make sure you read Error Documents and Browser Behavior at the bottom of the page

like image 2
helloV Avatar answered Oct 17 '22 05:10

helloV