Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 673
Deyab Avatar asked Aug 16 '15 09:08

Deyab


People also ask

How do I give permission to S3 bucket?

Open the Amazon S3 console at https://console.aws.amazon.com/s3/ . Select the bucket that you want AWS Config to use to deliver configuration items, and then choose Properties. Choose Permissions. Choose Edit Bucket Policy.

What is the maximum allowed object size in S3?

Individual Amazon S3 objects can range in size from a minimum of 0 bytes to a maximum of 5 TB. The largest object that can be uploaded in a single PUT is 5 GB. For objects larger than 100 MB, customers should consider using the Multipart Upload capability.


1 Answers

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.

like image 70
Michael - sqlbot Avatar answered Oct 08 '22 19:10

Michael - sqlbot