Granting Temporary Uploads and Downloads with Presigned URLs
This lesson explains how a presigned URL grants time-limited access to upload or download a single object, so users can transfer files directly to or from Amazon S3 without AWS credentials and without routing data through your servers.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how a presigned URL carries a Signature Version 4 signature and expiry, and whose permissions it uses.
- Generate a presigned URL with the AWS SDK.
- Explain when a presigned POST is needed to enforce conditions such as a maximum file size.
- Distinguish S3 presigned URLs from CloudFront signed URLs.
How presigned URLs work
The application signs a request for one operation on one object with its own credentials, and embeds the Signature Version 4 signature and expiry in the URL's query string. Anyone holding the URL can perform that operation until it expires, with the permissions of whoever signed it.
- The signer must itself have permission for the operation, such as
s3:PutObjecton the key; the URL cannot grant more than the signer has. - The URL is valid until its expiry time or until the signing credentials expire, whichever comes first. A URL signed with temporary credentials, such as a Lambda role's, stops working when that session ends.
- The maximum expiry is 7 days when signed with an IAM user's long-term keys.
- The bucket stays private throughout; no bucket policy change is needed.
Generating presigned URLs
Example. A backend returns a presigned PUT URL valid for 10 minutes:
url = boto3.client("s3").generate_presigned_url(
"put_object",
Params={"Bucket": "photo-uploads", "Key": f"users/{user_id}/avatar.jpg", "ContentType": "image/jpeg"},
ExpiresIn=600,
)The client must send the same Content-Type that was signed, or S3 rejects the upload with SignatureDoesNotMatch. A download link can be created from the CLI:
aws s3 presign s3://reports/2026/q3.pdf --expires-in 3600Presigned POST for browser uploads
A presigned POST returns a URL and form fields for an HTML form upload. Its policy can enforce conditions that a presigned PUT cannot, such as a maximum file size, a key prefix or an allowed content type.
post = boto3.client("s3").generate_presigned_post(
Bucket="photo-uploads",
Key=f"users/{user_id}/${{filename}}",
Conditions=[["content-length-range", 1, 5 * 1024 * 1024], ["starts-with", "$Content-Type", "image/"]],
ExpiresIn=600,
)
# post["url"] and post["fields"] are sent to the browser to build the formPresigned URLs and CloudFront signed URLs
S3 presigned URLs and CloudFront signed URLs both give a user temporary access to private content without AWS credentials, but they work at different points.
A presigned URL is signed with the IAM credentials of whoever created it, and S3 checks the signature itself. It authorises one operation on one object, such as a GET to download a report or a PUT to upload a photo directly from a browser, and it carries the permissions of its creator: if the creator's role cannot read the object, or its temporary credentials expire, the URL stops working. A CloudFront signed URL or signed cookie is signed with a private key whose public key is registered in a trusted key group, and CloudFront checks it at the edge. Content is served from the cache, the bucket stays private behind origin access control, and signed cookies can cover many files at once. The CloudFront module describes signed URLs and cookies in detail.
The following table summarises the differences.
Browser uploads that bypass the server
Users upload profile photos through an API, and large uploads time out the API's 29-second limit. The redesign lets the browser upload directly to S3:
| Step | What happens |
|---|---|
| 1 | The browser asks the API for an upload URL |
| 2 | A Lambda function returns a presigned PUT URL valid for 5 minutes for uploads/{userId}/avatar.jpg |
| 3 | The browser PUTs the file straight to S3 (the bucket's CORS rule allows PUT from the app's origin) |
| 4 | An S3 event notification triggers a resize function |
The API no longer handles file bytes, and S3 absorbs any number of simultaneous uploads. The presigned URL carries the permissions of the function's role, so that role must allow s3:PutObject on the uploads prefix, and the URL stops working if those credentials expire first.
A presigned URL created with a Lambda function's role was given a 7-day expiry but stops working after a few hours. Why?
Show answer
A presigned URL is valid only while the credentials that signed it are valid. The role's temporary credentials expire within hours, so the URL expires with them.
Exam Tips
Remember for the exam
- To let users upload directly without AWS credentials, use a presigned URL.
- A presigned URL that stops working early was probably signed with credentials that have expired.
- To limit the size or type of browser uploads, use a presigned POST with policy conditions.
- A presigned URL carries the signer's permissions, so the signer must be allowed the operation.