0

I'm currently using a lambda to created signed links for my s3 bucket, and these links are supposed to have an expiry time of 24 hours. However, when I check the returned link - all the expiry times are set to 15 minutes. I've changed the CORS configuration on the s3 server to 86400 (24 hours), but that hasn't seemed to have fixed it. The file retrieval works perfectly fine though.

I'm using the javascript s3 sdk for doing this, below is the piece of code that creates the signed url. What can I do to make it accept the expires time?

var EXPIRY_IN_SECONDS = 3600 * 24; // 24 hour

function createSignedDownloadUrl(options, callback) {

  if (!options || !options.fileName ) {
    return callback(new Error('Invalid input.'));
  }

  var containsSpecialChars = /[^\u0000-\u00ff]/g.test(options.fileName);
  var contentDisposition;
  if (containsSpecialChars) {
    contentDisposition = 'inline; filename*=UTF-8\'\''+ encodeURIComponent(options.fileName);
  } else {
    contentDisposition = 'inline; filename="'+ options.fileName + '"; filename*=UTF-8\'\''+ encodeURIComponent(options.fileName);
  }
  var getObjectParams = {
    Bucket: options.s3Bucket,
    Key: options.s3Key,
    Expires: EXPIRY_IN_SECONDS,
    ResponseContentDisposition: contentDisposition,
  };

  s3.getSignedUrl('getObject', getObjectParams, callback);
}
Ramzi C.
  • 1,691
  • 1
  • 14
  • 27
  • Is the assignment of `var EXPIRY_IN_SECONDS = 3600 * 24;` occurring in the proper scope here? Move it inside the function. – Michael - sqlbot Mar 07 '17 at 00:16
  • It does appear to be in the right scope and moving it in doesn't change this. – Ramzi C. Mar 07 '17 at 20:12
  • Send `getObjectParams` to the console, please, and show it. The variable is in scope, but without seeing more code context, there is no evidence that it has a value at the time you use it. – Michael - sqlbot Mar 07 '17 at 23:36
  • I'm not going to post getObjectParams in its entirety for security reasons, but the value of expires is absolutely the value it says it is. – Ramzi C. Mar 08 '17 at 19:35
  • Does this mean that you logged it to the console and confirmed its value? – Michael - sqlbot Mar 08 '17 at 21:03

0 Answers0