Amazon S3: The request signature we calculated does not match the signature you provided
The request signature we calculated does not match the signature you provided. Check your key and signing method.Short answer
S3 computed a different signature from the one in your request. The usual causes are a wrong or mis-pasted secret access key, a server clock that is off, a proxy that edits headers or the query string, or presigned URL parameters that differ from the request. Test the same call from the AWS CLI to separate them.
Fix it fast
1Find out which cause you have
Run the same operation with the AWS CLI on the same server. If the CLI works, your PHP code or its credentials are wrong; if it fails too, look at the clock, key and network path.
date -u aws s3 ls s3://my-bucket --debug 2>&1 | tail -n 202Match what you see, then jump to its fix
- 1
SignatureDoesNotMatch for every request, even a simple listingThe secret access key is wrong or was pasted with extra charactersFix - 2
Starts suddenly on one server, or after a VM resume, while keys have not changedThe server clock is not synchronisedFix - 3
Works from a laptop or the CLI on the server but fails through a corporate proxy, load balancer or CDNA proxy or CDN changes the headers or query stringFix - 4
The URL was generated fine but the browser or client request fails with 403A presigned URL is used with a different method or headers than it was signed forFix
- 1
What does the error look like?
The request signature we calculated does not match the signature you provided. Check your key and signing method.Error SignatureDoesNotMatch, Status 403
Cause 1 of 4
The secret access key is wrong or was pasted with extra characters
1Check
AWS documentation for a related service describes this error as typically a copy and paste mistake: the secret key is wrong, or it does not belong to the access key ID. A trailing space or line break from a .env file is the usual form.
printf '[%s]\n' "$AWS_SECRET_ACCESS_KEY"
printf '%s' "$AWS_SECRET_ACCESS_KEY" | wc -c2Fix
Re-copy the pair from IAM, or create a new access key. Trim whitespace when you load it, and keep key and ID together.
<?php
$s3 = new Aws\S3\S3Client([
'region' => 'eu-west-1',
'version' => 'latest',
'credentials' => [
'key' => trim(getenv('AWS_ACCESS_KEY_ID')),
'secret' => trim(getenv('AWS_SECRET_ACCESS_KEY')),
],
]);3Verify
A simple call succeeds.
aws s3 ls s3://my-bucketConfirmed by docs.aws.amazon.com
Cause 2 of 4
The server clock is not synchronised
1Check
AWS lists an unsynchronised system clock first among the causes of SignatureDoesNotMatch, since even small drifts can invalidate signatures. Compare the server time with a trusted source.
timedatectl status2Fix
Turn on NTP time synchronisation.
sudo timedatectl set-ntp true3Verify
System clock synchronized: yes, then retry the request.
timedatectl status | grep -i synchronizedConfirmed by docs.aws.amazon.com
Cause 3 of 4
A proxy or CDN changes the headers or query string
1Check
AWS notes that some corporate proxies modify headers or query strings, which breaks the signature. Test without the proxy first.
curl -sI -o /dev/null -w '%{http_code}
' --noproxy '*' 'PRESIGNED_URL'2Fix
Send requests to S3 directly, or configure the proxy to pass the signed headers and the query string through unchanged.
# environment of the PHP process: bypass the proxy for AWS hosts
NO_PROXY=.amazonaws.com3Verify
The same request now returns 200.
curl -sI --noproxy '*' 'PRESIGNED_URL' | head -n 1Confirmed by docs.aws.amazon.com
Cause 4 of 4
A presigned URL is used with a different method or headers than it was signed for
1Check
The HTTP method, headers and query string must match exactly between generating the URL and using it. A URL signed for GET will not work for PUT.
curl -i -X PUT --upload-file ./test.txt 'PRESIGNED_PUT_URL'2Fix
Generate the URL for the exact command you will send (GetObject or PutObject), and send the same headers the signer included, such as Content-Type, if you signed them.
<?php
$cmd = $s3->getCommand('PutObject', ['Bucket' => 'my-bucket', 'Key' => 'a.txt']);
$req = $s3->createPresignedRequest($cmd, '+15 minutes');
echo (string) $req->getUri();3Verify
Upload with the matching method succeeds.
curl -i -X PUT --upload-file ./test.txt 'PRESIGNED_PUT_URL' | head -n 1Confirmed by docs.aws.amazon.com
How do I stop it coming back?
- Use IAM roles on EC2, ECS or Lambda, so no long-lived secret has to be pasted anywhere.
- Keep NTP enabled on every server.
- Store keys in a secret store and load them without surrounding whitespace.
- Let the SDK create presigned URLs instead of building signatures by hand.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
Related fixes
Back end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack end
Laravel cannot find League\Flysystem\AwsS3v3\AwsS3Adapter
Class 'League\Flysystem\AwsS3v3\AwsS3Adapter' not found
The S3 adapter package is missing, or your code names the class from an older Flysystem.
2 causes, each with a fixBack end
S3 PutObject fails in PHP with AccessDenied or AccessControlListNotSupported
because no identity-based policy allows the s3:PutObject action
A failed putObject() carries an HTTP status and an S3 error code in its message.
4 causes, each with a fixBack end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
Apache returns 403 when a URL contains %3F
a request like /page%3Fname=test is refused while /page?name=test works
Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.
2 causes, each with a fix