How to Get Signed S3 Url in AWS-SDK JS Version 3?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In AWS SDK for JavaScript v3, you generate a signed S3 URL with getSignedUrl from the request presigner package. The key pieces are an S3Client, the command you want to authorize, and an expiration time that controls how long the URL stays valid.
Install the Required Packages
For a basic S3 presigning setup, install the S3 client and the presigner helper.
Your code also needs working AWS credentials through the usual SDK resolution chain, such as environment variables, an IAM role, or a shared credentials file.
Generate a Signed URL for Downloading
The most common case is a signed GET URL for downloading an object.
That returns a URL clients can use for temporary access without exposing your AWS secret key.
Generate a Signed URL for Uploading
The same pattern works for uploads, but the command changes to PutObjectCommand.
A client can then send an HTTP PUT to that URL. The request headers must match the headers that were part of the signed command, especially things such as Content-Type.
Why v3 Looks Different from v2
In SDK v2, many examples used methods attached directly to the S3 service object. In v3, the SDK is more modular. You create command objects and then presign those commands.
That change is why v3 examples usually look like this sequence:
- Create
S3Client. - Create
GetObjectCommandorPutObjectCommand. - Pass both into
getSignedUrl.
Once you know that pattern, generating signed URLs becomes predictable.
Controlling Expiration
The expiresIn option is measured in seconds.
Shorter expiration times are usually better for security. Signed URLs should be valid only as long as the user or client actually needs them.
For S3 presigned URLs using Signature Version 4, the maximum practical lifetime is typically seven days.
Server-Side Utility Example
In an application, you usually wrap presigning in a small helper rather than scattering it through route handlers.
That keeps presigning logic consistent and makes it easier to change expiration policy in one place.
Common Pitfalls
A common mistake is installing only @aws-sdk/client-s3 and forgetting @aws-sdk/s3-request-presigner, which is where getSignedUrl lives in v3.
Another pitfall is signing a PutObjectCommand with headers such as ContentType, then sending an upload request that omits or changes those headers. The signature may fail because the actual request no longer matches what was signed.
Region mismatches also cause confusion. If the bucket is in a different region than the client configuration, the signed URL can fail even though the code looks correct.
Finally, do not generate signed URLs from unvalidated user input without checking bucket and key rules. Presigning is authorization, so your application should decide what objects a caller is allowed to access before generating the URL.
Summary
- In SDK v3, signed S3 URLs are created with
getSignedUrland an S3 command object. - Install both
@aws-sdk/client-s3and@aws-sdk/s3-request-presigner. - Use
GetObjectCommandfor downloads andPutObjectCommandfor uploads. - Keep
expiresInshort unless there is a real reason to extend it. - Make sure the signed command, region, and actual HTTP request headers all line up.
Related reading
- How to get the instance Name from the instance in AWS?
- How to get the region of the current user from boto?
- How to get the table name in AWS dynamodb trigger function?
- How to get the URL of a file on AWS S3 using aws-sdk?
- How to get the browser to navigate to URL in JavaScript
- How to get the browser viewport dimensions?
- How to get the user's canonical ID for adding a S3 permission
- How to get total number of pages in DynamoDB if we set a limit?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.