title: Upload files to S3 using AWS S3 static web hosting
body: <p>We have been looking at options for uploading files to S3. One option which we are looking at using S3 static web hosting. In this option we will have a page which I am trying to write a simple Index.html page with a upload option. I set the following Bucket Policy:</p>
  
  <pre><code>{
      "Version": "2012-10-17",
      "Statement": [
          {
              "Sid": "Allow Public Access to All Objects",
              "Effect": "Allow",
              "Principal": "*",
              "Action": [
                  "s3:GetObject",
                  "s3:PutObject"
              ],
              "Resource": "arn:aws:s3:::&lt;bucketname&gt;/*"
          }
      ]
  } 
  </code></pre>
  
  <p>The following is the CORS setting:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"&gt;
  &lt;CORSRule&gt;
      &lt;AllowedOrigin&gt;*&lt;/AllowedOrigin&gt;
      &lt;AllowedMethod&gt;GET&lt;/AllowedMethod&gt;
      &lt;AllowedMethod&gt;POST&lt;/AllowedMethod&gt;
      &lt;MaxAgeSeconds&gt;3000&lt;/MaxAgeSeconds&gt;
      &lt;AllowedHeader&gt;Authorization&lt;/AllowedHeader&gt;
  &lt;/CORSRule&gt;
  &lt;/CORSConfiguration&gt;
  </code></pre>
  
  <p>The following is the code in Index.html</p>
  
  <pre><code>&lt;html&gt;
  &lt;header&gt;&lt;title&gt;Hello World&lt;/title&gt;&lt;/header&gt;
  &lt;body&gt;
  Hello world
  
  &lt;form action="/action_page.php"&gt;
    &lt;input type="file" name="pic" accept="image/*"&gt;
    &lt;input type="submit"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I try accessing my s3 bucket with the webhosting URI, I am getting the page and when I try to upload the document I am getting the following error:</p>
  
  <pre><code>404 Not Found
  
  Code: NoSuchKey
  Message: The specified key does not exist.
  Key: action_page.php
  RequestId: &lt;requestid&gt;
  HostId: &lt;hostid&gt;
  An Error Occurred While Attempting to Retrieve a Custom Error Document
  
  Code: NoSuchKey
  Message: The specified key does not exist.
  Key: error.html
  </code></pre>
  
  <p>if I add the error.html page its showing my error page.</p>
  
  <p>Now is my thinking to use S3 webhosting to upload files to the bucket without any coding is the right way? What am I missing here?</p>