Share an object with a presigned URL
Give someone time-limited access to one object without a key, with a presigned URL.
A presigned URL grants access to one object until it expires. Replace example-uploads with your bucket's name and report.pdf with the object's key.
Prerequisites
- Permission for
s3:GetObjecton the object (s3:GetObjectVersionfor an older version), ors3:PutObjectfor an upload URL. The URL can do no more than the key or user that signs it.
Create the URL
Not available in Console. The console's **Download** uses such a URL for you but does not show it.
dcloud s3 bucket-objects download-url example-uploads --key report.pdfPOST /s3/api/buckets/example-uploads/objects/download-url
{ "key": "report.pdf" }The answer is { url, expiresInSeconds }: a URL valid for 900 seconds (15 minutes) that downloads
the object. upload-url (s3:PutObject) answers a URL to PUT one object, with the
Content-Type header it must carry, also valid 15 minutes.
With an S3 client you choose the lifetime, up to 7 days (604800 seconds):
aws --profile dcloud s3 presign s3://example-uploads/report.pdf --expires-in 3600Result
The URL works until it expires, then answers AccessDenied "Request has expired". A URL you
presigned with an S3 client stops working at once when you delete the access key that signed it.
The URL from download-url makes the browser save the object as a file. A browser on another site that loads the URL from a script
needs a CORS rule on the bucket (see
Let a web page use the bucket).