Ravindra BagaleCourses & study guides

14. Amazon S3: Buckets, Objects, Policies and Presigned URLs

14.6 Presigned URLs: Temporary Private Access

Bucket private aahe, pan user la ek video 10 minutes sathi baghu dyaycha aahe – kasa? Presigned URL. Server aaplya credentials ne ek URL "sign" karto; tya URL madhe expiry time aani signature asto. Expiry nantar URL band.

aws s3 presign s3://ravindra-demo-files-pune/site/index.html --expires-in 600   # 600 seconds

The output looks like this (shortened):

https://ravindra-demo-files-pune.s3.ap-south-1.amazonaws.com/site/index.html
  ?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA.../ap-south-1/s3/aws4_request
  &X-Amz-Date=20260927T043000Z&X-Amz-Expires=600&X-Amz-Signature=5f2c...

In PHP (AWS SDK for PHP – we use exactly this in the project chapter):

<?php
require __DIR__ . '/vendor/autoload.php';
$s3  = new Aws\S3\S3Client(['region' => 'ap-south-1']);   // credentials come from the IAM role
$cmd = $s3->getCommand('GetObject', ['Bucket' => 'ravindra-reels-media-pune', 'Key' => 'videos/a1.mp4']);
$url = (string) $s3->createPresignedRequest($cmd, '+15 minutes')->getUri();
echo $url;
Presigned URL fact Why it matters
Works for GET (download) and PUT (upload) Browsers can upload directly to S3 without your credentials
Signed with the signer's permissions If the role cannot read the object, the URL fails too
Anyone holding the URL can use it until expiry Keep expiry short; don't log or share them
Role-based (temporary) credentials The URL also stops working when those credentials expire

Why this matters for security

Presigned URLs let you keep the bucket 100% private and still serve files to logged-in users – the right design for user uploads. But they are bearer tokens (वाहक टोकन): whoever has the link has access. Short expiry, HTTPS only, and never presigning keys that come straight from user input without checks (or a user could ask for someone else's file – an IDOR bug).

Ravindra Bagale's Tip

Khup students "soyi" mhanun presigned URL la 7 divsanchi expiry detat aani to URL WhatsApp var firto! Video feed sathi 10–20 minutes purese aahet – page reload zala ki navin URL banto. Aani laptop var aws s3 presign kelyavar 403 aala tar region bagha – bucket chya region madhech sign kara.

Lab

Upload a private image. Confirm its plain object URL returns AccessDenied in the browser. Generate a presigned URL with --expires-in 60, open it immediately, then open it again after two minutes and observe the expiry error.