0

I have a website containing my portfolio, which is hosted in an AWS S3 Bucket. it used to work fine, but suddenly the contact me section stopped working.

I have a javascript file, contact_me.js referring to a php file, contact_me.php. When I try to click "Send" to send a mail to my email adress, I get the error

"mail/contact_me.php:1 Failed to load resource: the server responded with a status of 403 (Forbidden)"

When I just navigate in my browser to the path, I download the file, so I do seem to have access to it.

I have also gotten this error, while trying to change permissions in AWS, but to no avail:

jquery.min.js:4
POST http://ReplacedWithDummySite/mail/contact_me.php 403 (Forbidden)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
submitSuccess @ contact_me.js:21
(anonymous) @ jqBootstrapValidation.js:76
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3

The line where it goes wrong is this: "g.send(b.hasContent && b.data || null)"

I have not done anything for this to break: it used to work just fine. I have checked the bucket permissions, since the obvious thing would be that the permissions are not public. I have set everything to public, and have the following bucket policy:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "AllowPublicRead",
        "Effect": "Allow",
        "Principal": "*",
        "Action": "s3:*",
        "Resource": "arn:aws:s3:::aws-website-dummyarn/*"
    }
 ]
}
Runey
  • 179
  • 1
  • 10
  • 1
    Your bucket policy allows *all* S3 actions to everyone. This is highly inadvisable. If you mean for it to provide public read access only, as the Sid suggests, then change the action to s3:GetObject. – jarmod May 28 '18 at 22:20
  • Thanks, I have changed that now. Still haven't solved the issue though, I've tried altering the bucket policy settings etc, but nothing seems to work. I've read a comment here "https://stackoverflow.com/questions/26691286/amazon-s3-bucket-returning-403-forbidden" by "Sthe", talking about system time. Could this be the issue? I have not found how to change system time, or if that even is relevant for me. – Runey May 28 '18 at 22:42

1 Answers1

0

I have a javascript file, contact_me.js referring to a php file, contact_me.php. When I try to click "Send" to send a mail to my email adress, I get the error

...it used to work just fine.

You may be under that impression, but is genuinely not possible for this setup to have ever worked on S3.

S3 doesn't support PHP, or any server-side language. S3 has never supported server-side scripting.

You can host a static website on Amazon Simple Storage Service (Amazon S3). On a static website, individual webpages include static content. They might 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.

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

The fact that you can download the file only indicates that it is stored on S3. A web server that actually supports PHP would not let you download the file -- it would execute the file, on the server, and return the output that was generated.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
  • Interesting, I could have sworn that it uses to work. I guess I only tested it locally. Thanks – Runey May 29 '18 at 05:52