Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pre-Signed S3 URLs with Cloudfront/CDN

Is it possible to generate pre-signed URLs for CDNs (i.e., CloudFront?), or can I append pre-signed URL parameters to a CloudFront URL to use instead?

Example:

string url = amazonS3Client.generatePresignedUrl(generatePresignedUrlRequest);

returns:

url = "https://bucket-name.s3.amazonaws.com/file.txt?AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXX&Expires=1111111111&Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Can I take the URL parameters and append to corresponding CloudFront URL:

https://00000000000000.cloudfront.net/file.txt?AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXX&Expires=1111111111&Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Will this work to allow download of the file?

like image 821
Ken K Avatar asked Oct 17 '16 19:10

Ken K


1 Answers

FYI if you only want the network optimization, and not the edge caching, you can also consider using "Amazon S3 Transfer Acceleration": https://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html

This allows you to keep using S3 signatures, rather than having to implement Cloudfront signatures.

See my answer here for more details: https://stackoverflow.com/a/54139603/8046487

like image 177
Mathieu Rey Avatar answered Oct 18 '22 21:10

Mathieu Rey