The Problem That Started Everything
A month ago, I was architecting a file service for our microservices platform. The requirements seemed straightforward: multiple client applications needed to upload files, different file types with varying size limits, no AWS credentials should ever leave our backend, sub-100ms response times for URL generation, and the ability to handle 50,000+ uploads per hour during peak traffic.
I immediately knew the traditional proxy approach was wrong—having clients upload to our backend, which then proxies everything to S3, would create obvious bottlenecks. The backend becomes a single point of failure, bandwidth costs double, latency increases for large files, and server resources get wasted on proxying.
I had heard about pre-signed URLs as the elegant solution—direct client-to-S3 uploads without exposing credentials. Perfect! But as I started implementing them, I realized I had no idea how they actually worked under the hood.
I expected my backend to be calling some AWS API to generate these URLs, maybe something like
createPreSignedUrl(). But as I dug deeper into the documentation and started experimenting, I
discovered something that absolutely blew my mind: the AWS SDK generates these URLs entirely on my
machine, using only my AWS credentials and some cryptographic magic.
There was no API call to AWS. No network request. No validation step. The SDK was creating these URLs locally and somehow AWS would just... trust them?
This fundamental realization kept me up at night: How can AWS trust a URL that was generated entirely on my machine, without ever validating it with their servers?
I knew pre-signed URLs were the right architectural choice, but I needed to understand this magic. The answer I discovered reveals one of the most elegant distributed authorization systems ever built.
Understanding S3's Architectural Philosophy
To understand pre-signed URLs, you need to understand how Amazon designed S3 from the ground up.
The RESTful Foundation
S3 was built on a simple principle: every object is addressable via HTTP. When AWS launched S3 in 2006, they made a crucial architectural decision:
h t t p s : / / b u c k e t - n a m e . s 3 . a m a z o n a w s . c o m / o b j e c t - k e y
This wasn't just a URL scheme—it was a commitment to HTTP semantics:
GETretrieves objectsPUTuploads objectsDELETEremoves objectsHEADgets metadata- Standard HTTP status codes
- Standard HTTP headers
The Authentication Challenge
But HTTP alone isn't secure. AWS needed a way to:
- Authenticate requests (prove who you are)
- Authorize operations (prove what you can do)
- Scale to billions of requests per day
- Maintain sub-millisecond latency
Their solution was revolutionary: embed authentication directly into the HTTP request.
How Pre-Signed URLs Actually Work
The Cryptographic Foundation
Pre-signed URLs use AWS Signature Version 4 (SigV4), which is based on HMAC-SHA256. Here's what happens when you generate a pre-signed URL:
/ / S i m p l i f i e d v e r s i o n o f w h a t t h e A W S S D K d o e s i n t e r n a l l y
f u n c t i o n c r e a t e P r e s i g n e d U r l ( c r e d e n t i a l s , r e q u e s t , e x p i r e s I n ) {
/ / 1 . C r e a t e c a n o n i c a l r e q u e s t
c o n s t c a n o n i c a l R e q u e s t = c r e a t e C a n o n i c a l R e q u e s t ( r e q u e s t ) ;
/ / 2 . C r e a t e s t r i n g t o s i g n
c o n s t s t r i n g T o S i g n = c r e a t e S t r i n g T o S i g n ( c a n o n i c a l R e q u e s t , c r e d e n t i a l s . r e g i o n ) ;
/ / 3 . C a l c u l a t e s i g n a t u r e
c o n s t s i g n a t u r e = c a l c u l a t e S i g n a t u r e ( s t r i n g T o S i g n , c r e d e n t i a l s . s e c r e t K e y ) ;
/ / 4 . A p p e n d s i g n a t u r e t o U R L
r e t u r n ` $ { r e q u e s t . u r l } ? $ { s i g n a t u r e } & X - A m z - E x p i r e s = $ { e x p i r e s I n } ` ;
}
The Canonical Request Format
The canonical request includes every detail that AWS needs to validate:
P U T
/ m y - b u c k e t / u p l o a d / u s e r - 1 2 3 / p r o f i l e . j p g
h o s t = m y - b u c k e t . s 3 . a m a z o n a w s . c o m & x - a m z - d a t e = 2 0 2 5 0 6 0 9 T 1 2 0 0 0 0 Z
h o s t : m y - b u c k e t . s 3 . a m a z o n a w s . c o m
x - a m z - c o n t e n t - s h a 2 5 6 : U N S I G N E D - P A Y L O A D
x - a m z - d a t e : 2 0 2 5 0 6 0 9 T 1 2 0 0 0 0 Z
h o s t ; x - a m z - c o n t e n t - s h a 2 5 6 ; x - a m z - d a t e
U N S I G N E D - P A Y L O A D
Key insight: This canonical format ensures that any modification to the request (different path, different headers, different method) will invalidate the signature.
The Trust Model
When S3 receives a request with a pre-signed URL:
- Extracts the signature and metadata from query parameters
- Reconstructs the canonical request from the actual HTTP request
- Calculates what the signature should be using the same algorithm
- Compares calculated signature with provided signature
- Allows or denies the request based on the match
Crucially: AWS never needs to store or look up the pre-signed URL. The URL itself contains all the information needed for validation.
Deep Dive: S3's Internal Architecture
Here’s a clean written (markdown-friendly) version of your explanation for "How S3 Scales Authorization"—with diagrams replaced by readable text steps:
How S3 Scales Authorization
Traditional authorization systems look like this:
- Request is received
- It goes to the Auth Service
- Auth Service performs a Database Lookup
- It then runs a Permission Check
- Finally, it returns Allow or Deny
S3's approach:
- Request comes with a Pre-signed URL
- S3 Extracts the Signature from the request
- It then Recalculates the Signature based on expected inputs
- Compares Signatures
- Returns Allow or Deny
Benefits:
- No database lookups required
- Horizontally scalable (stateless)
- Sub-millisecond latency
- Works across all regions without synchronization
The Storage Layer
S3's storage architecture is built on several key principles:
1. Objects are Immutable Once uploaded, an S3 object never changes. Updates create new versions.
2. Metadata is Separate from Data Object metadata is stored in a distributed index, separate from the actual file data.
3. Geographic Replication Objects are automatically replicated across multiple Availability Zones within a region.
4. Eventual Consistency Model S3 provides read-after-write consistency for new objects, eventual consistency for overwrites and deletes.
How This Enables Pre-Signed URLs
The immutable nature of S3 objects means that pre-signed URLs can be cached safely. When you generate a pre-signed URL for a specific object version, that URL will always refer to the same data.
Google Cloud Storage: A Different Philosophy
Google took a fundamentally different approach with Cloud Storage, reflecting their experience with distributed systems at scale.
Service Account-Based Architecture
Instead of HMAC signatures, Google uses RSA private keys:
/ / G o o g l e C l o u d S t o r a g e a p p r o a c h
a s y n c f u n c t i o n g e n e r a t e S i g n e d U r l ( s e r v i c e A c c o u n t , b u c k e t N a m e , f i l e N a m e ) {
c o n s t o p t i o n s = {
v e r s i o n : " v 4 " ,
a c t i o n : " w r i t e " ,
e x p i r e s : D a t e . n o w ( ) + 1 5 * 6 0 * 1 0 0 0 , / / 1 5 m i n u t e s
} ;
c o n s t [ u r l ] = a w a i t s t o r a g e . b u c k e t ( b u c k e t N a m e ) . f i l e ( f i l e N a m e ) . g e t S i g n e d U r l ( o p t i o n s ) ;
r e t u r n u r l ;
}
Key Differences from AWS
| Aspect | AWS S3 | Google Cloud Storage |
|---|---|---|
| Signing Algorithm | HMAC-SHA256 | RSA-SHA256 |
| Key Management | AWS manages secrets | You manage private keys |
| URL Structure | Query parameters | Query parameters + policy |
| Maximum Expiry | 7 days | 7 days |
| Offline Generation | Yes (with credentials) | Yes (with private key) |
Google's Policy-Based Approach
Google Cloud Storage signed URLs can include complex policies:
{
" c o n d i t i o n s " : [
{ " b u c k e t " : " m y - b u c k e t " } ,
[ " s t a r t s - w i t h " , " $ k e y " , " u p l o a d s / " ] ,
{ " a c l " : " b u c k e t - o w n e r - r e a d " } ,
[ " c o n t e n t - l e n g t h - r a n g e " , 0 , 1 0 4 8 5 7 6 0 ]
]
}
This allows for more granular control but at the cost of complexity.
Performance Characteristics
Google's Advantages:
- Better integration with Google's global network
- More granular access control
- Better audit logging
AWS's Advantages:
- Simpler mental model
- Faster URL generation (symmetric crypto vs asymmetric)
- More mature ecosystem
Implementation Deep-Dive: Building Production-Ready File Service
Let me show you how I built our production file service, including all the edge cases and optimizations.
The Complete NestJS Implementation
/ / f i l e . s e r v i c e . t s
i m p o r t { S 3 C l i e n t , P u t O b j e c t C o m m a n d , G e t O b j e c t C o m m a n d } f r o m " @ a w s - s d k / c l i e n t - s 3 " ;
i m p o r t { g e t S i g n e d U r l } f r o m " @ a w s - s d k / s 3 - r e q u e s t - p r e s i g n e r " ;
i m p o r t { I n j e c t a b l e , B a d R e q u e s t E x c e p t i o n } f r o m " @ n e s t j s / c o m m o n " ;
i m p o r t { C o n f i g S e r v i c e } f r o m " @ n e s t j s / c o n f i g " ;
i n t e r f a c e U p l o a d U r l R e q u e s t {
f i l e N a m e : s t r i n g ;
c o n t e n t T y p e : s t r i n g ;
c o n t e n t L e n g t h : n u m b e r ;
u s e r I d : s t r i n g ;
f o l d e r ? : s t r i n g ;
}
i n t e r f a c e U p l o a d U r l R e s p o n s e {
u p l o a d U r l : s t r i n g ;
d o w n l o a d U r l : s t r i n g ;
k e y : s t r i n g ;
e x p i r e s A t : D a t e ;
}
@ I n j e c t a b l e ( )
e x p o r t c l a s s F i l e S e r v i c e {
p r i v a t e r e a d o n l y s 3 : S 3 C l i e n t ;
p r i v a t e r e a d o n l y b u c k e t N a m e : s t r i n g ;
p r i v a t e r e a d o n l y r e g i o n : s t r i n g ;
p r i v a t e r e a d o n l y m a x F i l e S i z e = 1 0 0 * 1 0 2 4 * 1 0 2 4 ; / / 1 0 0 M B
c o n s t r u c t o r ( p r i v a t e c o n f i g S e r v i c e : C o n f i g S e r v i c e ) {
t h i s . b u c k e t N a m e = t h i s . c o n f i g S e r v i c e . g e t ( " A W S _ S 3 _ B U C K E T " ) ;
t h i s . r e g i o n = t h i s . c o n f i g S e r v i c e . g e t ( " A W S _ R E G I O N " , " u s - e a s t - 1 " ) ;
t h i s . s 3 = n e w S 3 C l i e n t ( {
r e g i o n : t h i s . r e g i o n ,
c r e d e n t i a l s : {
a c c e s s K e y I d : t h i s . c o n f i g S e r v i c e . g e t ( " A W S _ A C C E S S _ K E Y _ I D " ) ,
s e c r e t A c c e s s K e y : t h i s . c o n f i g S e r v i c e . g e t ( " A W S _ S E C R E T _ A C C E S S _ K E Y " ) ,
} ,
} ) ;
}
a s y n c g e n e r a t e U p l o a d U r l ( r e q u e s t : U p l o a d U r l R e q u e s t ) : P r o m i s e < U p l o a d U r l R e s p o n s e > {
/ / V a l i d a t i o n
t h i s . v a l i d a t e U p l o a d R e q u e s t ( r e q u e s t ) ;
/ / G e n e r a t e u n i q u e k e y
c o n s t k e y = t h i s . g e n e r a t e O b j e c t K e y ( r e q u e s t ) ;
/ / C r e a t e p r e s i g n e d U R L f o r u p l o a d
c o n s t u p l o a d C o m m a n d = n e w P u t O b j e c t C o m m a n d ( {
B u c k e t : t h i s . b u c k e t N a m e ,
K e y : k e y ,
C o n t e n t T y p e : r e q u e s t . c o n t e n t T y p e ,
C o n t e n t L e n g t h : r e q u e s t . c o n t e n t L e n g t h ,
M e t a d a t a : {
" u s e r - i d " : r e q u e s t . u s e r I d ,
" o r i g i n a l - n a m e " : r e q u e s t . f i l e N a m e ,
" u p l o a d - t i m e s t a m p " : n e w D a t e ( ) . t o I S O S t r i n g ( ) ,
} ,
} ) ;
c o n s t e x p i r e s I n = 3 0 0 ; / / 5 m i n u t e s
c o n s t u p l o a d U r l = a w a i t g e t S i g n e d U r l ( t h i s . s 3 , u p l o a d C o m m a n d , { e x p i r e s I n } ) ;
/ / G e n e r a t e c o r r e s p o n d i n g d o w n l o a d U R L
c o n s t d o w n l o a d C o m m a n d = n e w G e t O b j e c t C o m m a n d ( {
B u c k e t : t h i s . b u c k e t N a m e ,
K e y : k e y ,
} ) ;
c o n s t d o w n l o a d U r l = a w a i t g e t S i g n e d U r l ( t h i s . s 3 , d o w n l o a d C o m m a n d , {
e x p i r e s I n : 3 6 0 0 , / / 1 h o u r
} ) ;
r e t u r n {
u p l o a d U r l ,
d o w n l o a d U r l ,
k e y ,
e x p i r e s A t : n e w D a t e ( D a t e . n o w ( ) + e x p i r e s I n * 1 0 0 0 ) ,
} ;
}
p r i v a t e v a l i d a t e U p l o a d R e q u e s t ( r e q u e s t : U p l o a d U r l R e q u e s t ) : v o i d {
/ / F i l e s i z e v a l i d a t i o n
i f ( r e q u e s t . c o n t e n t L e n g t h > t h i s . m a x F i l e S i z e ) {
t h r o w n e w B a d R e q u e s t E x c e p t i o n (
` F i l e s i z e $ { r e q u e s t . c o n t e n t L e n g t h } e x c e e d s m a x i m u m $ { t h i s . m a x F i l e S i z e } `
) ;
}
/ / C o n t e n t t y p e v a l i d a t i o n
c o n s t a l l o w e d T y p e s = [
" i m a g e / j p e g " ,
" i m a g e / p n g " ,
" i m a g e / g i f " ,
" a p p l i c a t i o n / p d f " ,
" t e x t / p l a i n " ,
" v i d e o / m p 4 " ,
" v i d e o / q u i c k t i m e " ,
] ;
i f ( ! a l l o w e d T y p e s . i n c l u d e s ( r e q u e s t . c o n t e n t T y p e ) ) {
t h r o w n e w B a d R e q u e s t E x c e p t i o n ( ` C o n t e n t t y p e $ { r e q u e s t . c o n t e n t T y p e } n o t a l l o w e d ` ) ;
}
/ / F i l e n a m e v a l i d a t i o n
i f ( ! / ^ [ a - z A - Z 0 - 9 . _ - ] + $ / . t e s t ( r e q u e s t . f i l e N a m e ) ) {
t h r o w n e w B a d R e q u e s t E x c e p t i o n ( " I n v a l i d f i l e n a m e f o r m a t " ) ;
}
}
p r i v a t e g e n e r a t e O b j e c t K e y ( r e q u e s t : U p l o a d U r l R e q u e s t ) : s t r i n g {
c o n s t t i m e s t a m p = D a t e . n o w ( ) ;
c o n s t r a n d o m I d = M a t h . r a n d o m ( ) . t o S t r i n g ( 3 6 ) . s u b s t r i n g ( 2 ) ;
c o n s t f o l d e r = r e q u e s t . f o l d e r | | " u p l o a d s " ;
c o n s t e x t e n s i o n = r e q u e s t . f i l e N a m e . s p l i t ( " . " ) . p o p ( ) ;
r e t u r n ` $ { f o l d e r } / $ { r e q u e s t . u s e r I d } / $ { t i m e s t a m p } - $ { r a n d o m I d } . $ { e x t e n s i o n } ` ;
}
}
Advanced Features: Multipart Upload Support
For large files, S3 supports multipart uploads. Here's how to generate pre-signed URLs for each part:
a s y n c g e n e r a t e M u l t i p a r t U p l o a d U r l s (
k e y : s t r i n g ,
p a r t C o u n t : n u m b e r
) : P r o m i s e < { u p l o a d I d : s t r i n g ; u r l s : s t r i n g [ ] } > {
/ / I n i t i a t e m u l t i p a r t u p l o a d
c o n s t c r e a t e C o m m a n d = n e w C r e a t e M u l t i p a r t U p l o a d C o m m a n d ( {
B u c k e t : t h i s . b u c k e t N a m e ,
K e y : k e y ,
} ) ;
c o n s t { U p l o a d I d } = a w a i t t h i s . s 3 . s e n d ( c r e a t e C o m m a n d ) ;
/ / G e n e r a t e p r e s i g n e d U R L s f o r e a c h p a r t
c o n s t u r l s = a w a i t P r o m i s e . a l l (
A r r a y . f r o m ( { l e n g t h : p a r t C o u n t } , a s y n c ( _ , i ) = > {
c o n s t p a r t C o m m a n d = n e w U p l o a d P a r t C o m m a n d ( {
B u c k e t : t h i s . b u c k e t N a m e ,
K e y : k e y ,
P a r t N u m b e r : i + 1 ,
U p l o a d I d ,
} ) ;
r e t u r n g e t S i g n e d U r l ( t h i s . s 3 , p a r t C o m m a n d , { e x p i r e s I n : 3 6 0 0 } ) ;
} )
) ;
r e t u r n { u p l o a d I d : U p l o a d I d , u r l s } ;
}
Security Deep-Dive: Attack Vectors and Mitigations
Common Security Pitfalls
1. URL Leakage Pre-signed URLs in server logs, browser history, or referrer headers.
Mitigation:
/ / U s e s h o r t e x p i r y t i m e s
c o n s t s h o r t L i v e d U r l = a w a i t g e t S i g n e d U r l ( s 3 , c o m m a n d , { e x p i r e s I n : 3 0 0 } ) ;
/ / L o g o n l y t h e k e y , n e v e r t h e f u l l U R L
l o g g e r . i n f o ( ` G e n e r a t e d u p l o a d U R L f o r k e y : $ { k e y } ` ) ;
2. Replay Attacks Someone intercepts and reuses a pre-signed URL.
Mitigation:
/ / A d d n o n c e t o p r e v e n t r e p l a y
c o n s t c o m m a n d = n e w P u t O b j e c t C o m m a n d ( {
B u c k e t : b u c k e t ,
K e y : k e y ,
M e t a d a t a : {
n o n c e : c r y p t o . r a n d o m U U I D ( ) ,
" c l i e n t - i p " : r e q u e s t . i p ,
} ,
} ) ;
3. Path Traversal Malicious users trying to access unauthorized paths.
Mitigation:
p r i v a t e s a n i t i z e K e y ( u s e r I n p u t : s t r i n g , u s e r I d : s t r i n g ) : s t r i n g {
/ / R e m o v e a n y p a t h t r a v e r s a l a t t e m p t s
c o n s t s a n i t i z e d = u s e r I n p u t . r e p l a c e ( / \ . \ . / g , ' ' ) . r e p l a c e ( / \ / / g , ' _ ' ) ;
/ / A l w a y s s c o p e t o u s e r ' s d i r e c t o r y
r e t u r n ` u s e r s / $ { u s e r I d } / $ { s a n i t i z e d } ` ;
}
Advanced Security: Custom Authorization
You can add additional validation layers:
a s y n c v a l i d a t e U p l o a d P e r m i s s i o n ( u s e r I d : s t r i n g , k e y : s t r i n g ) : P r o m i s e < b o o l e a n > {
/ / C h e c k u s e r q u o t a
c o n s t u s e r U s a g e = a w a i t t h i s . g e t U s e r S t o r a g e U s a g e ( u s e r I d ) ;
i f ( u s e r U s a g e > t h i s . g e t U s e r Q u o t a ( u s e r I d ) ) {
r e t u r n f a l s e ;
}
/ / C h e c k f i l e t y p e r e s t r i c t i o n s b a s e d o n u s e r t i e r
c o n s t u s e r T i e r = a w a i t t h i s . g e t U s e r T i e r ( u s e r I d ) ;
c o n s t a l l o w e d T y p e s = t h i s . g e t A l l o w e d T y p e s F o r T i e r ( u s e r T i e r ) ;
r e t u r n a l l o w e d T y p e s . i n c l u d e s ( t h i s . g e t C o n t e n t T y p e F r o m K e y ( k e y ) ) ;
}
Performance Optimization Strategies
1. URL Generation Caching
@ I n j e c t a b l e ( )
e x p o r t c l a s s O p t i m i z e d F i l e S e r v i c e {
p r i v a t e u r l C a c h e = n e w M a p < s t r i n g , { u r l : s t r i n g ; e x p i r e s A t : D a t e } > ( ) ;
a s y n c g e t C a c h e d U p l o a d U r l ( k e y : s t r i n g ) : P r o m i s e < s t r i n g > {
c o n s t c a c h e d = t h i s . u r l C a c h e . g e t ( k e y ) ;
i f ( c a c h e d & & c a c h e d . e x p i r e s A t > n e w D a t e ( ) ) {
r e t u r n c a c h e d . u r l ;
}
/ / G e n e r a t e n e w U R L w i t h b u f f e r t i m e
c o n s t u r l = a w a i t t h i s . g e n e r a t e U p l o a d U r l ( k e y ) ;
c o n s t e x p i r e s A t = n e w D a t e ( D a t e . n o w ( ) + 2 4 0 0 0 0 ) ; / / 4 m i n u t e s ( 5 m i n U R L - 1 m i n b u f f e r )
t h i s . u r l C a c h e . s e t ( k e y , { u r l , e x p i r e s A t } ) ;
r e t u r n u r l ;
}
}
2. Batch URL Generation
a s y n c g e n e r a t e B a t c h U p l o a d U r l s ( r e q u e s t s : U p l o a d U r l R e q u e s t [ ] ) : P r o m i s e < U p l o a d U r l R e s p o n s e [ ] > {
/ / P r o c e s s i n p a r a l l e l f o r b e t t e r p e r f o r m a n c e
r e t u r n P r o m i s e . a l l (
r e q u e s t s . m a p ( r e q u e s t = > t h i s . g e n e r a t e U p l o a d U r l ( r e q u e s t ) )
) ;
}
3. Regional Optimization
p r i v a t e g e t O p t i m a l R e g i o n ( u s e r L o c a t i o n : s t r i n g ) : s t r i n g {
c o n s t r e g i o n M a p = {
' U S ' : ' u s - e a s t - 1 ' ,
' E U ' : ' e u - w e s t - 1 ' ,
' A P A C ' : ' a p - s o u t h e a s t - 1 ' ,
} ;
r e t u r n r e g i o n M a p [ u s e r L o c a t i o n ] | | ' u s - e a s t - 1 ' ;
}
Monitoring and Observability
Key Metrics to Track
1. URL Generation Performance
@ I n j e c t a b l e ( )
e x p o r t c l a s s M e t r i c s S e r v i c e {
a s y n c t r a c k U r l G e n e r a t i o n ( s t a r t T i m e : n u m b e r , s u c c e s s : b o o l e a n , r e g i o n : s t r i n g ) {
c o n s t d u r a t i o n = D a t e . n o w ( ) - s t a r t T i m e ;
/ / C u s t o m m e t r i c s
t h i s . p r o m e t h e u s . h i s t o g r a m ( " p r e s i g n e d _ u r l _ g e n e r a t i o n _ d u r a t i o n _ m s " , d u r a t i o n ) ;
t h i s . p r o m e t h e u s . c o u n t e r ( " p r e s i g n e d _ u r l _ g e n e r a t i o n _ t o t a l " , { s u c c e s s , r e g i o n } ) ;
}
}
2. Upload Success Rates
/ / C l o u d W a t c h c u s t o m m e t r i c
a w a i t t h i s . c l o u d W a t c h . p u t M e t r i c D a t a ( {
N a m e s p a c e : " F i l e S e r v i c e " ,
M e t r i c D a t a : [
{
M e t r i c N a m e : " U p l o a d S u c c e s s R a t e " ,
V a l u e : s u c c e s s R a t e ,
U n i t : " P e r c e n t " ,
D i m e n s i o n s : [ { N a m e : " E n v i r o n m e n t " , V a l u e : " p r o d u c t i o n " } ] ,
} ,
] ,
} ) ;
Error Handling and Alerting
@ C a t c h ( S 3 S e r v i c e E x c e p t i o n )
e x p o r t c l a s s S 3 E x c e p t i o n F i l t e r i m p l e m e n t s E x c e p t i o n F i l t e r {
c a t c h ( e x c e p t i o n : S 3 S e r v i c e E x c e p t i o n , h o s t : A r g u m e n t s H o s t ) {
c o n s t c t x = h o s t . s w i t c h T o H t t p ( ) ;
c o n s t r e s p o n s e = c t x . g e t R e s p o n s e < R e s p o n s e > ( ) ;
/ / L o g f o r m o n i t o r i n g
t h i s . l o g g e r . e r r o r ( " S 3 o p e r a t i o n f a i l e d " , {
e r r o r : e x c e p t i o n . n a m e ,
c o d e : e x c e p t i o n . $ m e t a d a t a ? . h t t p S t a t u s C o d e ,
r e q u e s t I d : e x c e p t i o n . $ m e t a d a t a ? . r e q u e s t I d ,
} ) ;
/ / R e t u r n u s e r - f r i e n d l y e r r o r
r e s p o n s e . s t a t u s ( 5 0 0 ) . j s o n ( {
m e s s a g e : " F i l e o p e r a t i o n f a i l e d " ,
t i m e s t a m p : n e w D a t e ( ) . t o I S O S t r i n g ( ) ,
} ) ;
}
}
Comparison: Pre-Signed URLs vs Alternatives
Alternative 1: Server-Side Proxy
/ / T r a d i t i o n a l a p p r o a c h - D O N ' T d o t h i s f o r l a r g e f i l e s
@ P o s t ( ' u p l o a d ' )
a s y n c u p l o a d F i l e ( @ U p l o a d e d F i l e ( ) f i l e : E x p r e s s . M u l t e r . F i l e ) {
/ / F i l e g o e s t h r o u g h y o u r s e r v e r - b a n d w i d t h 2 x , l a t e n c y h i g h
r e t u r n t h i s . s 3 . u p l o a d ( {
B u c k e t : ' b u c k e t ' ,
K e y : ' k e y ' ,
B o d y : f i l e . b u f f e r ,
} ) . p r o m i s e ( ) ;
}
Problems:
- Server bandwidth usage
- Memory usage for large files
- Single point of failure
- Increased latency
Alternative 2: Client-Side AWS SDK
/ / C l i e n t - s i d e - D O N ' T d o t h i s
c o n s t s 3 = n e w A W S . S 3 ( {
a c c e s s K e y I d : " Y O U R _ K E Y " , / / ❌ N E V E R e x p o s e c r e d e n t i a l s
s e c r e t A c c e s s K e y : " Y O U R _ S E C R E T " , / / ❌ S e c u r i t y n i g h t m a r e
} ) ;
Problems:
- Credentials exposure
- No fine-grained control
- Client-side secrets
Alternative 3: STS Temporary Credentials
/ / M o r e c o m p l e x b u t m o r e f l e x i b l e
c o n s t s t s C l i e n t = n e w S T S C l i e n t ( { r e g i o n : " u s - e a s t - 1 " } ) ;
c o n s t a s s u m e R o l e C o m m a n d = n e w A s s u m e R o l e C o m m a n d ( {
R o l e A r n : " a r n : a w s : i a m : : a c c o u n t : r o l e / U p l o a d R o l e " ,
R o l e S e s s i o n N a m e : ` u p l o a d - s e s s i o n - $ { u s e r I d } ` ,
} ) ;
c o n s t c r e d e n t i a l s = a w a i t s t s C l i e n t . s e n d ( a s s u m e R o l e C o m m a n d ) ;
/ / R e t u r n t e m p o r a r y c r e d e n t i a l s t o c l i e n t
Comparison Table:
| Approach | Complexity | Security | Performance | Cost |
|---|---|---|---|---|
| Pre-signed URLs | Low | High | Excellent | Low |
| Server Proxy | Medium | High | Poor | High |
| Client SDK | Low | Very Poor | Good | Low |
| STS Credentials | High | High | Good | Medium |
Real-World Challenges and Solutions
Challenge 1: Large File Uploads
Problem: Users uploading 1GB+ video files with unreliable connections.
Solution: Implement resumable uploads with multipart strategy:
c l a s s R e s u m a b l e U p l o a d S e r v i c e {
a s y n c i n i t i a t e R e s u m a b l e U p l o a d ( f i l e S i z e : n u m b e r , f i l e N a m e : s t r i n g ) {
c o n s t c h u n k S i z e = 1 0 * 1 0 2 4 * 1 0 2 4 ; / / 1 0 M B c h u n k s
c o n s t p a r t C o u n t = M a t h . c e i l ( f i l e S i z e / c h u n k S i z e ) ;
c o n s t { u p l o a d I d , u r l s } = a w a i t t h i s . g e n e r a t e M u l t i p a r t U p l o a d U r l s ( f i l e N a m e , p a r t C o u n t ) ;
r e t u r n {
u p l o a d I d ,
c h u n k S i z e ,
t o t a l P a r t s : p a r t C o u n t ,
u p l o a d U r l s : u r l s ,
} ;
}
a s y n c c o m p l e t e R e s u m a b l e U p l o a d ( u p l o a d I d : s t r i n g , p a r t s : C o m p l e t e d P a r t [ ] ) {
c o n s t c o m p l e t e C o m m a n d = n e w C o m p l e t e M u l t i p a r t U p l o a d C o m m a n d ( {
B u c k e t : t h i s . b u c k e t N a m e ,
K e y : t h i s . k e y ,
U p l o a d I d : u p l o a d I d ,
M u l t i p a r t U p l o a d : { P a r t s : p a r t s } ,
} ) ;
r e t u r n t h i s . s 3 . s e n d ( c o m p l e t e C o m m a n d ) ;
}
}
Challenge 2: Rate Limiting
Problem: Users generating too many pre-signed URLs.
Solution: Implement intelligent rate limiting:
@ I n j e c t a b l e ( )
e x p o r t c l a s s R a t e L i m i t e d F i l e S e r v i c e {
p r i v a t e r a t e L i m i t e r = n e w M a p < s t r i n g , { c o u n t : n u m b e r ; r e s e t T i m e : n u m b e r } > ( ) ;
a s y n c c h e c k R a t e L i m i t ( u s e r I d : s t r i n g ) : P r o m i s e < b o o l e a n > {
c o n s t n o w = D a t e . n o w ( ) ;
c o n s t w i n d o w = 6 0 0 0 0 ; / / 1 m i n u t e
c o n s t l i m i t = 1 0 0 ; / / 1 0 0 U R L s p e r m i n u t e
c o n s t u s e r L i m i t = t h i s . r a t e L i m i t e r . g e t ( u s e r I d ) ;
i f ( ! u s e r L i m i t | | n o w > u s e r L i m i t . r e s e t T i m e ) {
t h i s . r a t e L i m i t e r . s e t ( u s e r I d , { c o u n t : 1 , r e s e t T i m e : n o w + w i n d o w } ) ;
r e t u r n t r u e ;
}
i f ( u s e r L i m i t . c o u n t > = l i m i t ) {
r e t u r n f a l s e ;
}
u s e r L i m i t . c o u n t + + ;
r e t u r n t r u e ;
}
}
Challenge 3: Cost Optimization
Problem: S3 requests and data transfer costs adding up.
Solution: Implement intelligent caching and regional optimization:
c l a s s C o s t O p t i m i z e d F i l e S e r v i c e {
a s y n c g e t O p t i m i z e d U p l o a d U r l ( r e q u e s t : U p l o a d U r l R e q u e s t ) {
/ / U s e I n t e l l i g e n t T i e r i n g f o r a u t o m a t i c c o s t o p t i m i z a t i o n
c o n s t c o m m a n d = n e w P u t O b j e c t C o m m a n d ( {
B u c k e t : t h i s . b u c k e t N a m e ,
K e y : t h i s . g e n e r a t e K e y ( r e q u e s t ) ,
S t o r a g e C l a s s : " I N T E L L I G E N T _ T I E R I N G " ,
/ / A d d l i f e c y c l e r u l e s v i a S 3 c o n s o l e o r C l o u d F o r m a t i o n
} ) ;
r e t u r n g e t S i g n e d U r l ( t h i s . s 3 , c o m m a n d , { e x p i r e s I n : 3 0 0 } ) ;
}
/ / U s e C l o u d F r o n t f o r d o w n l o a d U R L s t o r e d u c e S 3 c o s t s
a s y n c g e t O p t i m i z e d D o w n l o a d U r l ( k e y : s t r i n g ) {
c o n s t c l o u d F r o n t U r l = ` h t t p s : / / d 1 2 3 4 5 6 7 8 9 0 . c l o u d f r o n t . n e t / $ { k e y } ` ;
/ / G e n e r a t e s i g n e d C l o u d F r o n t U R L i n s t e a d o f S 3
r e t u r n t h i s . g e n e r a t e C l o u d F r o n t S i g n e d U r l ( c l o u d F r o n t U r l ) ;
}
}
The Future of Object Storage Authorization
Emerging Patterns
1. Zero-Trust Architecture Every request is verified, even from internal services.
2. Policy-as-Code Fine-grained permissions defined in version-controlled policies.
3. Real-time Revocation Ability to instantly revoke access to pre-signed URLs.
AWS Innovations on the Horizon
S3 Object Lambda: Transform objects on-the-fly during retrieval.
/ / F u t u r e : D y n a m i c o b j e c t t r a n s f o r m a t i o n
c o n s t t r a n s f o r m e d U r l = a w a i t s 3 . g e t S i g n e d U r l ( " g e t O b j e c t " , {
B u c k e t : " m y - b u c k e t " ,
K e y : " i m a g e . j p g " ,
R e s p o n s e C o n t e n t T y p e : " i m a g e / w e b p " , / / A u t o m a t i c c o n v e r s i o n
R e s p o n s e C a c h e C o n t r o l : " m a x - a g e = 3 6 0 0 " ,
} ) ;
S3 Access Grants: More granular access control coming soon.
What This Means for Developers
The trend is toward more granular, policy-driven access control while maintaining the simplicity that makes pre-signed URLs so powerful.
Key Takeaways
Pre-signed URLs represent a masterclass in distributed systems design:
1. Stateless Authorization: No server-side state required for validation.
2. Cryptographic Trust: Security through mathematics rather than databases.
3. HTTP Native: Works with existing web infrastructure seamlessly.
4. Horizontal Scalability: No bottlenecks, scales to billions of requests.
5. Developer Ergonomics: Simple to implement, hard to misuse.
The elegance lies not in complexity, but in how a simple cryptographic signature can replace an entire authorization infrastructure.
When you generate a pre-signed URL, you're not just creating a temporary link—you're participating in one of the most successful distributed authorization systems ever built.
Next time you use a pre-signed URL, remember: you're holding a cryptographically signed contract that AWS has never seen, will never store, but will always trust. That's the beauty of well-designed distributed systems.