Lesson 4 of 7 Amazon S3

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:PutObject on 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.

The following diagram shows a browser upload with a presigned URL.

A presigned upload. The browser asks the application for an upload URL; the application signs a PUT for one object with its own credentials and an expiry; the browser uploads the file straight to the private bucket with that URL. The URL is valid until its expiry or until the signing credentials expire, whichever comes first.
The file goes directly from the browser to S3, so the application never handles its bytes and the bucket never becomes public.

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 3600
Scenario questions

Presigned URLs in practice

Exam skills 2.1.4

Practise the rules that decide whether a presigned URL works.

Log in to try this activity Interactive activities are free with an account.

Presigned 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 form

Presigned 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.

S3 presigned URL
Served fromS3 directly
Signed withIAM credentials
CoversOne object and one operation
Typical useUploads and occasional downloads
CloudFront signed URL or cookie
Served fromCloudFront edge locations
Signed withA CloudFront key pair in a trusted key group
CoversOne file (URL) or many files (cookies)
Typical useDistributing private content at scale
True or false

Presigned or CloudFront signed?

Exam skills 2.1.4

Check three facts about the two kinds of temporary access.

Log in to try this activity Interactive activities are free with an account.
Worked example

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:

StepWhat happens
1The browser asks the API for an upload URL
2A Lambda function returns a presigned PUT URL valid for 5 minutes for uploads/{userId}/avatar.jpg
3The browser PUTs the file straight to S3 (the bucket's CORS rule allows PUT from the app's origin)
4An 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.

Check yourself

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.