S3 REST API PUT POST method

+2 votes
I ve manged to sign in  with AWS S3 Rest API. When I use correct REST verb for creating resource, namely POST, I encounter this error '405 method not allowed'. Same request works fine with method PUT and creates resource.

Am I doing something wrong?
Apr 9, 2018 in AWS by hemant
• 5,790 points
10,778 views

4 answers to this question.

+1 vote

This where I feel is the problem lies that is while mapping CRUD to HTTP methods.

Understand this, POST may not be the best method to create resource. This is because semantics of other methods are determined by the HTTP protocol, but the semantics of POST are determined by the target media type itself. 

POST is used for creation, but can be used for updates.  It's wrong to use POST for retrieval, since you have GET standardized for that, but it's fine to use POST for creating a resource when the client can't use PUT for some reason.

PUT on the other hand is not the "correct method for updating resource". 

PUT is the method used to replace a resource completely, ignoring its current state. It's not right to use PUT for partial updates, because you're asking for the server to consider the current state of the resource. PATCH is the method to do that.

These are the definitions:

  • POST: Takes in data, applies it to the resource identified by the given URI, here the rules you documented for the resource media type are followed.

  • PUT: It will replace whatever is identified by the given URI with this data, and ignore whatever is in there already, if anything.

  • PATCH: if the resource identified by the given URI still has the same state it had the last time, apply this diff to it.

It is possible to create with POST and PUT, but not PATCH, because it is dependent on current state. You can update with any of them, but with PATCH you have an update conditional to the state you want to update from, with PUT you update by replacing the whole entity, so it's an idempotent operation, and with POST you ask the server to do it according to predefined rules.

answered Apr 9, 2018 by code_ninja
• 6,300 points
+1 vote

From the http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

POST:

The posted entity is subordinate to the URI in the same way that a file is subordinate to a directory containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a database

The action performed by the POST method might not result in a resource that can be identified by a URI. In this case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the response includes an entity that describes the result

If a resource has been created on the origin server, the response SHOULD be 201 (Created)

PUT:

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI. If a new resource is created, the origin server MUST inform the user agent via the 201 (Created) response. If an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request

answered Oct 25, 2018 by Nabarupa
+1 vote
The HTTP methods POST and PUT, they both serve a different purpose. It's quite possible, valid and even preferred in some occasions, to use PUT to create resources, or use POST to update resources.

Use PUT when you can update a resource completely through a specific resource.

If you do not know the actual resource location, for instance, when you add a new article, but do not have any idea where to store it, you can POST it to an URL, and let the server decide the actual URL.
answered Oct 25, 2018 by traveller
+1 vote
The POST verb is most-often utilized to **create** new resources. In particular, it's used to create subordinate resources.

PUT is most-often utilized for **update** capabilities, PUT-ing to a known resource URI with the request body containing the newly-updated representation of the original resource.
answered Oct 25, 2018 by regina phillange

Related Questions In AWS

0 votes
1 answer

How to use AWS S3 REST API ListObjects(v2) with multiple parent/child bucket directories?

Here you have to use the ListObjectsV2 ...READ MORE

answered Feb 15, 2022 in AWS by anonymous
1,308 views
+1 vote
4 answers

Can a URL be directly uploaded to S3 using POST?

You can read this blog and get ...READ MORE

answered Oct 25, 2018 in AWS by chamunda
3,286 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
11,401 views
+1 vote
3 answers

Not able to pass params POST to AWS Lambda from Amazon API Gateway

For this template : application/x-www-form-urlencoded  This line below will ...READ MORE

answered Jun 13, 2018 in AWS by Cloud gunner
• 4,670 points
8,744 views
0 votes
1 answer
0 votes
1 answer
+2 votes
3 answers
0 votes
1 answer

S3 Static Website Hosting Route All Paths to Index.html

Yes there is an easy way to ...READ MORE

answered Apr 8, 2018 in AWS by code_ninja
• 6,300 points
3,439 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP