Amazon S3 - 405 Method Not allowed using POST (Although I allowed POST on the bucket)

17,769

The direct cause of the error is unrelated to CORS, and is actually caused by the fact that that the S3 website endpoints don't support POST (only the REST endpoints support it, but that's not actually related to the problem at hand).

The real problem is that you appear to be trying to use S3 for something it doesn't do.

 $.ajax({
     url: 'graph-data.php',
     type: 'POST',

S3 is an object store, not an application server.

You can't run php on S3. You can't execute any server-side code on S3.

You can host a static website on Amazon S3. On a static website, individual web pages include static content. They may also contain client-side scripts. By contrast, a dynamic website relies on server-side processing, including server-side scripts such as PHP, JSP, or ASP.NET. Amazon S3 does not support server-side scripting.

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

That same page of the documentation will point you to alternative AWS solutions for accomplishing what you want.

Share:
17,769
Deyab
Author by

Deyab

Updated on June 16, 2022

Comments

  • Deyab
    Deyab almost 2 years

    I am facing a problem that my graph (Using AJAX - POST - PHP) is not appearing on Amazon

    http://cdpmotest.s3-website.eu-central-1.amazonaws.com/

    its says (Wrong Method 405 Error)

    This is my CORS Config :

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

    And this is my Script:

    <script>
    $(document).ready(function(){
         var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
         $.ajax({
             url: 'graph-data.php',
             type: 'POST',
             dataType: 'json',
             success: function(data) {
                  var array1 = data.map(function(item) {
                      return parseInt(item[1], 10);
                  });
                  var array2 = data.map(function(item) {
                      return parseInt(item[2], 10);
                  });
    
                  createGraph(array1, array2);
             }
         });//end AJAX request
    
    function createGraph(array1, array2) {
         var ctx = document.getElementById("chart-area1").getContext("2d");
         var barChartData = {
         labels : ["Land Acquisition","Design Concept","Permits and  Licensing","Tendering","Elec.+Water Requests","Construction Start","Construction Finish","Site Handover"],
         datasets : [
         {
              fillColor : "rgba(0,154,166,0.5)",
              strokeColor : "rgba(0,154,166,0.8)",
              highlightFill: "rgba(0,154,166,0.75)",
              highlightStroke: "rgba(0,154,166,1)",
              data : array1
         },
         {
              fillColor : "rgba(77,79,83,0.5)",
              strokeColor : "rgba(77,79,83,0.8)",
              highlightFill : "rgba(77,79,83,0.75)",
              highlightStroke : "rgba(77,79,83,1)",
              data : array2
        }
        ]
        }//end bar chart data
    
        window.myBar = new Chart(ctx).Bar(barChartData, {
            responsive : true
        });
        }//end createGraph
        });
        </script>
    

    Its working fine on localhost (WAMPServer)

    Can you help me please?

  • Deyab
    Deyab over 8 years
    I see.... I even tried using GET and it didn't work.. The Error 405 Disappeared when I used GET , But the Graph didnt appear.Though it appeared on the Localhost using GET
  • Michael - sqlbot
    Michael - sqlbot over 8 years
    Well, right, but not relevant, because the error isn't really about POST. You can't run php or any other server side language on S3.