How To Extend Duration Of Amazon S3 Signed Link In Elixir Arc — Tentamen Software Testing Blog

Image for post
Image for post

TL;DR

This post explains how to change default Elixir Arc S3 Signed Link expiration time.

Elixir Arc

Elixir Arc is a valuable Elixir library that enables developers to store files to Amazon S3 buckets from a Web application. In Arc Github readme page, there is documentation on how to create a signed URL:

# To generate a signed url:
Avatar.url({“selfie.png”, user}, :thumb, signed: true)

Signed URL is publically available, but hard to guess URL, something like this:

https://s3.amazonaws.com/testivator-screenshots/uploads/6014025768d341a596125c1a78e10ff3.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJ52D3Q6SY3S6QFRQ%2F20200827%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200827T112700Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=648b9983b241b5b78a451ef428109448cb5bac3b3e4263fa35ee5e4246e75ecc

Link expiration parameter is X-Amz-Expires=300 where 300 is default Arc value in seconds. How to change that value? An important thing with Open Source Elixir is that readable code is publically available. We searched Arc Github repo for the word signed and we found this line:

https://github.com/stavro/arc/blob/b67649c88a0bfefa568db0b2e7f9c203eef83d8d/lib/arc/storage/s3.ex#L78

Which gives us the following code for setting sign expiration time:

Avatar.url({“selfie.png”, user}, :thumb, [signed: true, expires_in: 36_000])

With this, we set the expiration time to ten hours.

Originally published at https://blog.tentamen.eu on August 31, 2020.

Written by

Founder of Tentamen, software testing agency.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store