There are cases where I want to send a file to someone, but I either don't want the attachment to live in their email inbox or message history, or maybe the file is too large to practically send that way. So I opt to use an S3 bucket to house the file.
But I also don't want a public bucket nor do I want the link to the file to persist forever. Enter an expiring, presigned URL--courtesy of AWS S3.
-
Run
bundleto install required gems. -
Copy the
.env.sampleto.envand configure as necessary. If you setS3_BUCKET, you can provide just the key you wish to sign. You will need to setAWS_REGIONto the region your bucket resides if you do not already have this set in your environment.
Run:
./signurl s3://<bucket>/<key>or if you have S3_BUCKET set in the .env file:
./signurl <key>By default, the link will expiry in 86,400 seconds (24 hours); however, you can override this by setting S3_URL_EXPIRY to the number of seconds you want your link to last. Note that this may also be subject to the maximum session duration if your credentials come from assuming a role: it will be the lesser of the two no matter what you set.