Skip to content

An S3 Download Link Says Seven Days. Why Did It Expire After an Hour?

By

In this article

A merchant needs seven days to download a settlement export. The application asks for an S3 presigned URL valid for seven days. An hour later, the link fails with ExpiredToken, even though its query string still says X-Amz-Expires=604800.

Here's the illustrative setup: the export is a private, immutable CSV in an S3 general purpose bucket in us-east-1. At 09:00 UTC, the app signs a GET with a role session that expires at 10:00. The merchant needs access for a week, but this session has one hour left. Extending the URL's requested lifetime doesn't make those clocks match.

We'll walk through a design that keeps the link in the merchant's email pointed at the authenticated application. S3 still serves the bytes, but each new download attempt starts with an access check the app can repeat.

What the presigner actually produces

A presigned URL packages a signed request for another client. With SigV4 query authentication, the signature binds the HTTP method, path, query parameters, and signed headers. X-Amz-Credential contains the access-key ID followed by a scope consisting of the date, Region, service, and aws4_request. Temporary credentials also include an X-Amz-Security-Token query parameter.

The URL holder can make that request repeatedly while its constraints permit. That's what makes it a bearer capability. They don't get the secret key to sign arbitrary requests. Changing X-Amz-Expires in the address bar changes signed data and invalidates the signature.

Once you have credentials, generating the URL is local work. S3 checks authorization when the request arrives. Here's a small offline example with fake credentials:

from urllib.parse import parse_qs, urlsplit
import boto3
from botocore.config import Config

s3 = boto3.client(
    "s3", region_name="us-east-1",
    aws_access_key_id="ASIAEXAMPLEOFFLINEKEY",
    aws_secret_access_key="offline-example-secret-not-an-aws-key",
    aws_session_token="offline-example-session-token",
    config=Config(signature_version="s3v4"),
)
url = s3.generate_presigned_url(
    "get_object",
    Params={"Bucket": "merchant-exports-example",
            "Key": "exports/merchant-42/export-2026-05.csv"},
    ExpiresIn=7 * 24 * 60 * 60,
)
query = parse_qs(urlsplit(url).query)
print(query["X-Amz-Expires"][0])
print("X-Amz-Security-Token" in query)

For this illustrative input, the expected output is 604800 and True. No request goes to AWS and these fake credentials don't have access to S3. Producing this URL shows how signing works, not that downloading will succeed.

We set SigV4 explicitly because the Boto3 API reference warns about compatibility behavior with SigV2. In real application code, use a supported temporary credential provider instead of explicit values like these.

Only 7 days? There are more tests than that!

Per AWS, a presigned request is a delegation under the signing principal's authority. S3 evaluates the request when it arrives. The signature's timing window, the credentials' validity, and applicable authorization policies all matter.

For our example case, assuming no earlier denial:

Check Bound on a new request
Signed at 09:00 with X-Amz-Expires=604800 Seven days after signing
Signing session expires at 10:00 One hour after signing
Bucket denies signatures older than ten minutes Ten minutes after signing, if configured

Seven days is SigV4's maximum requested duration, expressed here in seconds. It can't extend the role session. Even without the bucket restriction, a new request at 10:01 will fail because the credentials have expired. If the application signs at 09:45 with that same session, only 15 minutes remain. A newly generated URL doesn't imply newly issued credentials.

There's prior art here. In botocore issue #2604, a user reported URLs expiring with their underlying credentials despite a longer requested lifetime. Refreshing the app's credentials can help future signatures, but it can't fix URLs already sent to merchants.

The policy clock is separate again. Here's a statement to merge into your existing bucket policy, scoped to these export downloads:

{
  "Sid": "DenyOldExportDownloadSignatures",
  "Effect": "Deny",
  "Principal": "*",
  "Action": ["s3:GetObject", "s3:GetObjectVersion"],
  "Resource": "arn:aws:s3:::merchant-exports-example/exports/*",
  "Condition": {
    "StringEquals": { "s3:authType": "REST-QUERY-STRING" },
    "NumericGreaterThan": { "s3:signatureAge": "600000" }
  }
}

s3:signatureAge uses milliseconds, so 600,000 is ten minutes. Age begins at the signed timestamp, not the first click. This statement grants nothing and denies matching requests older than that threshold, including version-specific reads. It limits the signer's choice; it can't extend credentials.

Permissions aren't frozen into the URL. If a bucket policy starts denying the export, or the signer loses effective access, an otherwise unexpired request can fail. AWS's security FAQ ties authorization to permissions at invocation. Network restrictions evaluate the downloader's request path, not where the signing app ran.

Revocation has operational consequences too. Revoking older role sessions affects other uses of those sessions. Policy changes can take time to propagate. This isn't an instantaneous, per-link cancel button.

A download can outlast its URL

Now shorten the URL lifetime to ten minutes while leaving the session valid until 10:00. A merchant begins downloading at 09:09:50 and is still downloading at 09:11. That doesn't contradict expiration: S3 checks URL expiration when the HTTP request begins. AWS documents that a download started before expiry can continue after it, while a restart after expiry fails.

The distinction becomes visible when the connection drops:

Event What changes
GET begins at 09:09:50 S3 admits the request while the URL is valid
Transfer continues at 09:11 Passing URL expiry does not itself stop it
Connection drops at 09:12 Continuing requires a new HTTP request
Client retries the expired URL The previous admission does not carry over

A ranged retry is still a new GetObject request and needs valid authorization. A client that supports recovery can get another URL and ask for the remaining bytes. A regular browser download won't magically find your refresh endpoint.

Resume needs stable object identity too. I'd bind the export to a key that doesn't get overwritten, or sign a specific version and grant the corresponding s3:GetObjectVersion permission. Otherwise, the first and second requests could retrieve different CSVs. Signed headers must match on a retry too; if Range was signed, the client can't freely change it.

This continuation rule applies to URL expiry. It doesn't guarantee what happens during every mid-transfer credential revocation or policy change, and it can't undo bytes already downloaded.

For the merchant, I'd send a stable app URL like /exports/export-42 that requires login. Clicking Download calls an authenticated endpoint, checks current access, and mints a short S3 URL.

The sequence is short on purpose:

  1. Authenticate the caller and load the export record by its application ID.
  2. Check current merchant membership, export ownership, readiness, and retention deadline.
  3. Resolve the immutable bucket and key from that server-owned record.
  4. Obtain valid temporary signing credentials and issue a GET URL with a short lifetime.
  5. Return the URL with Cache-Control: no-store; the client downloads directly from S3.

Give the signing role only the read access this workflow needs on the export prefix. The age restriction above doesn't supply that permission.

An opaque ID helps avoid exposing storage details, but it doesn't replace the authorization check. In QiTong Han's 2024 security assessment write-up, changing a receipt's object key caused an application to sign access to another user's receipt. The signer must decide which object this caller may read, not accept an arbitrary bucket and key to sign.

Five minutes would be my initial URL budget for this design, subject to observed click delays and retries. Where credential expiration is available, cap that budget by remaining session lifetime with a safety margin. If the remainder is too short, acquire fresh credentials through the supported provider flow or return a retryable application error. A refresh that reuses nearly expired credentials hasn't solved the problem.

AWS uses a similar timing choice in the S3 console's Download action: it currently generates a five-minute URL when clicked, using temporary credentials. AWS labels that console behavior as changeable, not a service contract.

The application owns renewal. After an interrupted transfer, the client returns to the authenticated endpoint and repeats the checks. If access was removed or retention elapsed, it gets no new URL. Otherwise it receives a fresh capability for the same export.

Removing merchant access stops renewal, but it doesn't cancel an S3 URL already issued by a role that still has access. That URL remains usable within its remaining limits.

Keep the requested duration and credential deadline in diagnostic metadata, alongside the S3 error code and request ID. Distinguish ExpiredToken from a signature mismatch or policy denial rather than retrying every failure indefinitely.

Treat the returned URL as a credential. Use HTTPS, redact its query from logs and analytics, and keep it out of support tickets. AWS's logging guidance explains why ordinary URI logging can disclose the signature. Log the application export ID instead.

Conclusion

Before extending a download timeout, inspect what must remain valid for a week: the merchant's entitlement, the retained export, or one bearer URL. For this workflow, I would keep the first two durable, issue the third on demand, and test the interrupted-download path alongside the happy path.