Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3 POST request to S3 with response 405

I have the following CORS configuration for S3 in order to use one of my buckets as a static website hosting:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
    </CORSRule>
</CORSConfiguration>

Then I have the following Edit Redirection Rules:

<RoutingRules>
    <RoutingRule>
    <Condition>
        <KeyPrefixEquals>abc</KeyPrefixEquals>
    </Condition>
    <Redirect>
        <HostName>myec2instance.com</HostName>
    </Redirect>
</RoutingRule>

What I want to do is when S3 receives a POST to /abc redirects the request and request body to my ec2 instance. The redirection rule is working properly (I was able to test this by switching POST to a GET request) but for any reason S3 is returning HTTPResponse 405 when the request is a POST. Any ideas why?

like image 673
user1126167 Avatar asked Feb 18 '15 20:02

user1126167


2 Answers

This isn't CORS related -- it's S3 itself. The S3 website endpoints are only equipped for GET and HEAD. Anything else should be denied before the redirection rules are checked.

Website Endpoint

Supports only GET and HEAD requests on objects.

— http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html

like image 85
Michael - sqlbot Avatar answered Nov 15 '22 07:11

Michael - sqlbot


If you want to use POST request to S3, you need to use root object in your browser by creating POSTPolicy to get S3 authentication

you can refer Browser-Based Upload using HTTP POST

like image 26
Sasra S Avatar answered Nov 15 '22 06:11

Sasra S