Amazon S3 and CloudFront link expiration

s2Member tells Amazon to expire the link after 24 hours automatically.

In most cases, the download begins and ends after a single request, so 24 hours is more than enough time for a customer to connect to the file and begin downloading the file. It won't matter how long it takes them to download the file, as long as they connect within 24 hours.

This can become problematic if the person leaves the browser open to watch a video the following day, for example. 24 hours after the initial connection, the underlying link to the resource expires. So future attempts would require a new download link for the file, which can be done reloading the page.

Maybe you want to let the link live longer, or you feel 24 hours is too generous and you'd like it to expire sooner. s2Member has a filter that allows you to modify the default expiration time of 24 hours. So if you'd like to change the expiration time, you can certainly do that.

S3

Please create this directory and file:
/wp-content/mu-plugins/s2hacks.php
See: http://www.s2member.com/kb/hacking-s2member/

<?php 
add_filter('ws_plugin__s2member_amazon_s3_file_expires_time', 'my_s3_expiration_time');
function my_s3_expiration_time() {
  return '36 hours';
}

You can specify any length of time you like. Please use a string that is compatible with PHP's strtotime function. E.g.: 2 hours, 2 weeks, 10 days, are all valid periods of time.

CloudFront

The default expiration time on CloudFront integration is also 24 hours, and there is a filter for it as well.

<?php
add_filter('ws_plugin__s2member_amazon_cf_file_expires_time', 'my_cf_expiration_time');
function my_cf_expiration_time() {
  return '36 hours';
}

Leave a Reply

Your email address will not be published. Required fields are marked *