Summary card: hand-built SigV4 signature f0e8bdb8... equals botocore's; wrong header order changes it

Every S3 call carries a signature: a 64-character hex string made from your secret key and the request. When it is wrong the server says SignatureDoesNotMatch and tells you nothing else useful. This page builds one signature by hand, with real numbers, so you can see which bytes go into it and what each mistake does.

We use the worked example from the AWS documentation (a ranged GET of <code>/test.txt</code> from <code>examplebucket</code>, dated 2013-05-24, with AWS's public example keys), compute every step in a few lines of Python, and compare with botocore. Both give the documented signature <code>f0e8bdb87c964420e857bd35b5d6ed310bd44f0170aba48dd91039c6036bdb41</code>.

Step 1: the canonical request

Six parts, in this order, joined with newlines:

  • the method: GET (upper case)
  • the path, already URI-encoded: /test.txt
  • the query string, sorted: empty here, so an empty line
  • the headers, lower-case names, sorted, each as name:value plus a newline, then one more blank line
  • the list of signed header names: host;range;x-amz-content-sha256;x-amz-date
  • the SHA-256 of the body, or the string UNSIGNED-PAYLOAD. For an empty body it is e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
text
GET
/test.txt

host:examplebucket.s3.amazonaws.com
range:bytes=0-9
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20130524T000000Z

host;range;x-amz-content-sha256;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

SHA-256 of that text is <code>7344ae5b7ee6c3e7e6b0fe0640412a37625d1fbfff95c48bbb2dc43964946972</code>.

Step 2: the string to sign

text
AWS4-HMAC-SHA256
20130524T000000Z
20130524/us-east-1/s3/aws4_request
7344ae5b7ee6c3e7e6b0fe0640412a37625d1fbfff95c48bbb2dc43964946972

Algorithm name, the request timestamp, the credential scope (date / region / service / <code>aws4_request</code>) and the hash from step 1.

Step 3: the signing key

Four chained HMAC-SHA256 calls, each keyed with the previous result: start with <code>"AWS4" + secret</code>, then the date, the region, the service and the word <code>aws4_request</code>. For the example secret the result is <code>dbb893acc010964918f1fd433add87c70e8b0db6be30c1fbeafefa5ec6ba8378</code>. The key is tied to one day, one region and one service, so a leaked signing key is limited in scope.

Step 4: the signature

HMAC-SHA256 of the string to sign with that key, in hex: <code>f0e8bdb87c964420e857bd35b5d6ed310bd44f0170aba48dd91039c6036bdb41</code>. It goes into the header:

text
Authorization: AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/s3/aws4_request, SignedHeaders=host;range;x-amz-content-sha256;x-amz-date, Signature=f0e8bdb87c964420e857bd35b5d6ed310bd44f0170aba48dd91039c6036bdb41
python
import hashlib, hmac

def sha(b): return hashlib.sha256(b if isinstance(b, bytes) else b.encode()).hexdigest()
def mac(k, m): return hmac.new(k, m.encode(), hashlib.sha256).digest()

def sigv4(canonical, secret, date, amz_date, region, service="s3"):
    scope = f"{date}/{region}/{service}/aws4_request"
    to_sign = f"AWS4-HMAC-SHA256\n{amz_date}\n{scope}\n{sha(canonical)}"
    key = mac(mac(mac(mac(("AWS4" + secret).encode(), date), region), service), "aws4_request")
    return hmac.new(key, to_sign.encode(), hashlib.sha256).hexdigest()

We ran botocore 1.44.4's <code>S3SigV4Auth</code> on the same request with the clock fixed to 2013-05-24T00:00:00Z. Its Authorization header carried the same SignedHeaders and the same signature, character for character.

Ten ways to get SignatureDoesNotMatch

We changed one thing at a time in the canonical request or the inputs and recomputed. Any change gives a completely different signature, which is what the server sees when your client and its idea of the request disagree:

One changeFirst 16 hex of the signatureMatches AWS's?
none (correct)f0e8bdb87c964420yes
headers listed in the wrong order (date before content hash)979df24952689cedno
host header in upper case46b2b75019d8f4f7no
one trailing space in the Range valuef52f7d15ee36737cno
no blank line after the headers block845e44852fc05af7no
method written in lower case41c3b354355ec6b2no
range left out of the signed-headers list (but sent)b2506dbb8b93c74dno
body hash replaced by UNSIGNED-PAYLOAD453b26c1b8f3f068no
region eu-west-1 instead of us-east-18bdd9c6217292101no
date one day off in the scopee681f8aaa18a1e43no
secret key with a trailing newline (copied from a file)06a24f6e5ea950aano
  • Header problems are the most common cause in hand-written clients: sort by lower-case name, trim spaces, and sign exactly the headers you send.
  • The region in the scope must be the one the service expects. s3.tport.space uses region auto; sign with that, not us-east-1.
  • A secret read from a file keeps its newline unless you strip it. It never looks wrong when printed.

S3 specifics

  • The path is encoded once. Most AWS services encode the path twice in the canonical request; S3 does not. botocore's S3 signer returns the path untouched. For /my file.txt the right canonical path is /my%20file.txt; encoding twice gives /my%2520file.txt, and /café.txt becomes /caf%25C3%25A9.txt instead of /caf%C3%A9.txt. Our example path has no special characters, so both ways looked the same.
  • x-amz-content-sha256 is a required header on S3 and must hold the same value as the last canonical line. Use UNSIGNED-PAYLOAD over HTTPS if you do not want to hash the body first.
  • Presigned URLs use the same algorithm with the parameters in the query string and UNSIGNED-PAYLOAD as the payload hash.

Related: <a href="https://tport.space/articles/presigned-urls-or-public-files">presigned URLs or public files</a> and <a href="https://tport.space/articles/securing-webhook-upload-drops-s3-presigned-put">presigned PUT URLs with expiry and size limits</a>.

S3-compatible buckets with no egress fees. Signature Version 4 on every request, so any SDK or hand-written client works.

Explore tport.space

Test record and sources

  • Run 2026-11-17 on Windows 11 with Python 3.13 and botocore 1.44.4. Pure computation: no network, no account, no bucket. The example access key and secret are the public ones in the AWS documentation.
  • The mistake table is our own recomputation of the same canonical request with one change each; it shows the signature changes, not a server response.
  • Source: AWS, Signature Version 4 signing process and the Amazon S3 "Signature Calculations for the Authorization Header" example (GET Object with Range, examplebucket, 20130524, signature f0e8bdb8...).