Always set validity duration of presigned URLs with AWS S3 SDK

I was using Drive module of AdonisJS to generate a presigned URL for a document, without configuring when the document would expire – I was assuming that the default behavior would be to generate a URL that never expires. It appeared that the presigned URL was expiring 15 minutes after its generation.

Drive module is using getSignedUrl function from AWS S3 JavaScript SDK, which defaults to a validity of 15 minutes.

It’s necessary to set a validity duration suitable for your project. This is how to do it with Drive module of AdonisJS:

const presignedUrl = await Drive.getSignedUrl(path, {
expiresIn: '6 hours',