user1126167
user1126167

Reputation: 702

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?

Upvotes: 7

Views: 12373

Answers (2)

Sasra S
Sasra S

Reputation: 21

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

Upvotes: 1

Michael - sqlbot
Michael - sqlbot

Reputation: 179174

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

Upvotes: 14

Related Questions