William Worley
William Worley

Reputation: 844

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

Upvotes: 7

Views: 16871

Answers (3)

Maduabuchi
Maduabuchi

Reputation: 143

Try editing your bucket policy use "Action": "s3:GetObject"

Upvotes: 1

William Worley
William Worley

Reputation: 844

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.

Upvotes: 4

helloV
helloV

Reputation: 52393

Put your custome image in the document explained here

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

Upvotes: 2

Related Questions