At Slideshare, we use Amazon Web Services offerings and our main usage are of EC2, SQS and S3. We host almost all of our content at S3 because of scalability and reliability, it provides. For interacting with S3 via ruby, we use right_aws gem from Rightscale.
For finding a link for a private S3 object, we use get_link() method in right_aws. By default, get_link() returns a link, which remains valid for 24 hours. This is because default expiry time is set to 24 hours.
DEFAULT_EXPIRES_AFTER = 1 * 24 * 60 * 60 # One day's worth of seconds
I found out that the expires parameter passed to get_link() in s3_interface is limited to 1 year in seconds. For longer expires, it is required to pass (Time.now.utc + expires) in get_link() because of the following check:
expires ||= DEFAULT_EXPIRES_AFTER
expires = Time.now.utc + expires if expires.is_a?(Fixnum) && (expires < ONE_YEAR_IN_SECONDS)
expires = expires.to_i
When we call get_link(), it call generate_link() in turn and above code snippet is copied from generate_link(). You can see the function definition here.
Since finally, we recalculate the 'expires' in generate_link(), I fail to see the necessity of such a limitation.
I am writing this post so that one takes care while generating link using right_aws gem.
For 30 days expire (< one year), I'll use:
link = @s3_helper.get_link(bucket, key, expires = 30 * 24 * 60 * 60)
For 366 days (> one year) expire, I’ll use:
link = @s3_helper.get_link(bucket, key, expires = Time.now.utc + 366 * 24 * 60 * 60)
Subscribe - To get an automatic feed of all future posts subscribe here, or to receive them via email go here and enter your email address in the box. You can also like us on facebook and follow me on Twitter @akashag1001.