I have a ReactJs application that retrieves an S3 URL from the API and get a pre-signed version of it using the Amplify Storage
library.
This URL is the source of a video, the code is something like this:
Storage.get(
outputVideoSrc,
{ expires: 43200 }
));
But I have noticed that even tho the expiration time is really long, after ~1 hour the video stops playing, showing a message of Network error and aborting the playback.
If I get the video URL and try to access it from my browser I see an error similar to it:
<Error>
<Code>ExpiredToken</Code>
<Message>The provided token has expired.</Message>
<Token-0>
...
After some googling, I found that this expiration is due to the authentication token being expired, not the pre-signed URL per se. However, I need this URL to work for more than 1 hour, so the user can work with the video for long period of time.
It seems that it is not possible to customize how long the token will last on Amplify: https://github.com/aws-amplify/amplify-js/issues/2714
I have also tried to keep reloading the video after some time in the hope that I get a refreshed token, but:
- It doesn't work
- Even if it works I need to reload the video, which is terrible UI
Which alternatives do I have in order to make this work and not having the video stop playing all the time?