My website is hosted on s3 and served through a CloudFront distribution through HTTPS. an email to a specific address with basic info fields like name email and text. A few days ago it stopped working and now I am getting the following error whenever I try
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<AWSAccessKeyId>ASIA4OY4SXX6QO7ZXVHR</AWSAccessKeyId>
<StringToSign>AWS4-HMAC-SHA256 20231010T123140Z 20231010/us-east-1/s3/aws4_request 6f731b82a6d07a099b19ecc3de5cd8be10f31bb8842359c205c6f6025cee138b</StringToSign>
<SignatureProvided>90cb1fa85ea52b194e15e181d25566c2fdb2de130effe2e7fb71a1ac5df92cc2</SignatureProvided>
<StringToSignBytes>41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 32 33 31 30 31 30 54 31 32 33 31 34 30 5a 0a 32 30 32 33 31 30 31 30 2f 75 73 2d 65 61 73 74 2d 31 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 36 66 37 33 31 62 38 32 61 36 64 30 37 61 30 39 39 62 31 39 65 63 63 33 64 65 35 63 64 38 62 65 31 30 66 33 31 62 62 38 38 34 32 33 35 39 63 32 30 35 63 36 66 36 30 32 35 63 65 65 31 33 38 62</StringToSignBytes>
<CanonicalRequest>POST /send.php email=test%40gmail.com&name=test&phone=28287 host:3psync-web.s3.us-east-1.amazonaws.com x-amz-content-sha256:UNSIGNED-PAYLOAD x-amz-date:20231010T123140Z x-amz-security-token:IQoJb3JpZ2luX2VjEMv//////////wEaCWV1LXdlc3QtMSJHMEUCIQDSZSSwUFj5M40Pd3kM9mHY8dyuieF05x9iyz8QUCfk0QIgXh1JWhP9+ihOiX5Pvs+oGBbKXIbZTB7kBAx+w+XdBiYqvgII1P//////////ARAAGgw4NTYzNjkwNTMxODEiDCX45YJeWMf9uv4Z6iqSAoKlNoDcpLULyQcxs7ElaAGGFibCe/u7Jrguydb4m36nHkC59pFZN8d/0NIWlKyFUKhbMk85XSBoBaJFxxAfCzYuDDy1GtzV6pOZjLtsN5Rpjvw+iItyvOBKeq6fdKifleASgVZJyDj0tybYnv+qpRvEPPylB8rXnlVUR/BeizhgURvs3nwrk7+02g7D3AmOJ73VZPj5cfdBe2QgBNlNgwo/OfoeJyp+nhe1opgtbJFG1WC3YHXKRN1/gaUsozeu/2F1CwJ9pGHipwhFwwLc+IEP3npQNaLyV3Gupfu7BDLWxzsSXosoK9DmRBa9aPONAwlpqQXrEGQM7u20u2BVud8kI7H8nnTdIm5Y+yixDEJJzCEwvd6UqQY6jwEwl7FY8m/UNeZ6xLz2o+WGBYOtOTkI/CTUGchZC29ECv+DFgOgwqHJ6x4DdUpKK7Py8NfJr4fz8Pq58pssV4F7t6MQlSqeF2lrYSWl9teG+xbdLonL+M5b/qhBJ0ibsrMj+QAPh9/G37Nc6x+PK+BDQLKkh1loL3ERXilRp/MCcBQlhg4fqvkB1oL69HLgpA== x-amz-source-account:181119001231 x-amz-source-arn:arn:aws:cloudfront::181119001231:distribution/EJ7CZPX9K219J host;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-source-account;x-amz-source-arn UNSIGNED-PAYLOAD</CanonicalRequest>
<CanonicalRequestBytes>50 4f 53 54 0a 2f 73 65 6e 64 2e 70 68 70 0a 65 6d 61 69 6c 3d 68 73 61 64 69 61 35 33 38 25 34 30 67 6d 61 69 6c 2e 63 6f 6d 26 6e 61 6d 65 3d 48 61 6c 65 65 6d 61 26 70 68 6f 6e 65 3d 32 38 32 38 37 0a 68 6f 73 74 3a 33 70 73 79 6e 63 2d 77 65 62 2e 73 33 2e 75 73 2d 65 61 73 74 2d 31 2e 61 6d 61 7a 6f 6e 61 77 73 2e 63 6f 6d 0a 78 2d 61 6d 7a 2d 63 6f 6e 74 65 6e 74 2d 73 68 61 32 35 36 3a 55 4e 53 49 47 4e 45 44 2d 50 41 59 4c 4f 41 44 0a 78 2d 61 6d 7a 2d 64 61 74 65 3a 32 30 32 33 31 30 31 30 54 31 32 33 31 34 30 5a 0a 78 2d 61 6d 7a 2d 73 65 63 75 72 69 74 79 2d 74 6f 6b 65 6e 3a 49 51 6f 4a 62 33 4a 70 5a 32 6c 75 58 32 56 6a 45 4d 76 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 77 45 61 43 57 56 31 4c 58 64 6c 63 33 51 74 4d 53 4a 48 4d 45 55 43 49 51 44 53 5a 53 53 77 55 46 6a 35 4d 34 30 50 64 33 6b 4d 39 6d 48 59 38 64 79 75 69 65 46 30 35 78 39 69 79 7a 38 51 55 43 66 6b 30 51 49 67 58 68 31 4a 57 68 50 39 2b 69 68 4f 69 58 35 50 76 73 2b 6f 47 42 62 4b 58 49 62 5a 54 42 37 6b 42 41 78 2b 77 2b 58 64 42 69 59 71 76 67 49 49 31 50 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 41 52 41 41 47 67 77 34 4e 54 59 7a 4e 6a 6b 77 4e 54 4d 78 4f 44 45 69 44 43 58 34 35 59 4a 65 57 4d 66 39 75 76 34 5a 36 69 71 53 41 6f 4b 6c 4e 6f 44 63 70 4c 55 4c 79 51 63 78 73 37 45 6c 61 41 47 47 46 69 62 43 65 2f 75 37 4a 72 67 75 79 64 62 34 6d 33 36 6e 48 6b 43 35 39 70 46 5a 4e 38 64 2f 30 4e 49 57 6c 4b 79 46 55 4b 68 62 4d 6b 38 35 58 53 42 6f 42 61 4a 46 78 78 41 66 43 7a 59 75 44 44 79 31 47 74 7a 56 36 70 4f 5a 6a 4c 74 73 4e 35 52 70 6a 76 77 2b 69 49 74 79 76 4f 42 4b 65 71 36 66 64 4b 69 66 6c 65 41 53 67 56 5a 4a 79 44 6a 30 74 79 62 59 6e 76 2b 71 70 52 76 45 50 50 79 6c 42 38 72 58 6e 6c 56 55 52 2f 42 65 69 7a 68 67 55 52 76 73 33 6e 77 72 6b 37 2b 30 32 67 37 44 33 41 6d 4f 4a 37 33 56 5a 50 6a 35 63 66 64 42 65 32 51 67 42 4e 6c 4e 67 77 6f 2f 4f 66 6f 65 4a 79 70 2b 6e 68 65 31 6f 70 67 74 62 4a 46 47 31 57 43 33 59 48 58 4b 52 4e 31 2f 67 61 55 73 6f 7a 65 75 2f 32 46 31 43 77 4a 39 70 47 48 69 70 77 68 46 77 77 4c 63 2b 49 45 50 33 6e 70 51 4e 61 4c 79 56 33 47 75 70 66 75 37 42 44 4c 57 78 7a 73 53 58 6f 73 6f 4b 39 44 6d 52 42 61 39 61 50 4f 4e 41 77 6c 70 71 51 58 72 45 47 51 4d 37 75 32 30 75 32 42 56 75 64 38 6b 49 37 48 38 6e 6e 54 64 49 6d 35 59 2b 79 69 78 44 45 4a 4a 7a 43 45 77 76 64 36 55 71 51 59 36 6a 77 45 77 6c 37 46 59 38 6d 2f 55 4e 65 5a 36 78 4c 7a 32 6f 2b 57 47 42 59 4f 74 4f 54 6b 49 2f 43 54 55 47 63 68 5a 43 32 39 45 43 76 2b 44 46 67 4f 67 77 71 48 4a 36 78 34 44 64 55 70 4b 4b 37 50 79 38 4e 66 4a 72 34 66 7a 38 50 71 35 38 70 73 73 56 34 46 37 74 36 4d 51 6c 53 71 65 46 32 6c 72 59 53 57 6c 39 74 65 47 2b 78 62 64 4c 6f 6e 4c 2b 4d 35 62 2f 71 68 42 4a 30 69 62 73 72 4d 6a 2b 51 41 50 68 39 2f 47 33 37 4e 63 36 78 2b 50 4b 2b 42 44 51 4c 4b 6b 68 31 6c 6f 4c 33 45 52 58 69 6c 52 70 2f 4d 43 63 42 51 6c 68 67 34 66 71 76 6b 42 31 6f 4c 36 39 48 4c 67 70 41 3d 3d 0a 78 2d 61 6d 7a 2d 73 6f 75 72 63 65 2d 61 63 63 6f 75 6e 74 3a 31 38 31 31 31 39 30 30 31 32 33 31 0a 78 2d 61 6d 7a 2d 73 6f 75 72 63 65 2d 61 72 6e 3a 61 72 6e 3a 61 77 73 3a 63 6c 6f 75 64 66 72 6f 6e 74 3a 3a 31 38 31 31 31 39 30 30 31 32 33 31 3a 64 69 73 74 72 69 62 75 74 69 6f 6e 2f 45 4a 37 43 5a 50 58 39 4b 32 31 39 4a 0a 0a 68 6f 73 74 3b 78 2d 61 6d 7a 2d 63 6f 6e 74 65 6e 74 2d 73 68 61 32 35 36 3b 78 2d 61 6d 7a 2d 64 61 74 65 3b 78 2d 61 6d 7a 2d 73 65 63 75 72 69 74 79 2d 74 6f 6b 65 6e 3b 78 2d 61 6d 7a 2d 73 6f 75 72 63 65 2d 61 63 63 6f 75 6e 74 3b 78 2d 61 6d 7a 2d 73 6f 75 72 63 65 2d 61 72 6e 0a 55 4e 53 49 47 4e 45 44 2d 50 41 59 4c 4f 41 44</CanonicalRequestBytes>
<RequestId>0BTFDEJ81PQ0DJPZ</RequestId>
<HostId>XrFPn+rkcSaqjD3vRKQeu8TmJNzSA78PH5daVBZLyyDk9tZ/1VuDcC0DOjvkiFU9VEywMlgwDZpp3Yznsnj3ow==</HostId>
</Error>
I have tried several thread online but all of them mainly point to using incorrect keys or request format. I am not using the aws sdk at all in my code and its basic function using php mail function:
$to = "[email protected]";$subject = "Sign-Up";$headers = 'From: '.$email . "\r\n" ."MIME-Version: 1.0\n" ."Content-type: text/html; charset=iso-8859-1"
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
mail($to, $subject, $message, $headers); //This method sends the mail.
echo '<script type="text/javascript">
window.location.href = "thankyou.html";</script>';
}
else
{
echo '<script type="text/javascript">alert("Invalid Email, please provide an correct email.");</script>';
}}
else
{ echo $error;
}
There is no direct solution to this problem. After digging in for a day I found that it's impossible to do such processing on a static website on s3 which makes sense. I resolved this by making a lambda function on AWS to send emails and calling it within a client-side JS on my website. Everything is working now.
Reference: How to run PHP files on aws s3 bucket?