Sign me this sir !

340 mots | info ruby aws |

Sign me this sir !

Using AWS S3 for different projects (with carrierwave) my low level intellect could not help me to find the method to render a temporary signed url for private object in a bucket. If you have used some services using S3 you probably know what I’m talking about : a frackin’ long url with three vars (AWSAccessKeyId, Expires, Signature) stuck at the end.

The basic idea is that using the Expires time, your secret AWS Access Key, the path of the object you want (including the buckit) and a Sha digest you create a signature that AWS S3 will check to authotify the url. The timeout define, well, the expiration date of the url.

I looked around and found the specific page in Amazon s3 developper guide. So it ends up not too difficult to do by yourself.

Here’s the idea :

So, to make this usable we need first a method to properly encode the string. URI.escape doesn’t do the work we want, so we need to create a String method to replace all those strange characters (‘+’, ‘-’, ‘=’, …) by they proper url hex encodings.

Then we go define an Aws module, with a simple method to do the work :

And tada !

Now you just have to call it :