不良研究所

How to Generate Presigned URLs for Temporary Object Access

Dan Willoughby
August 2, 2022

The most common security breach with AWS S3 object storage is caused by misconfiguration.聽

If you do a quick Google search for 鈥渁ws public bucket breach鈥, you鈥檒l find, for example, and 鈥溾 that have happened in the last few years. Clearly we have a problem. Developers and businesses mistakenly create public AWS buckets to make it easier to access content, not realizing that anyone on the internet can also view the same data.

Using presigned URLs can keep data protected while also making it accessible to only those you share it with.

What is an AWS S3 presigned url?

For starters, S3 is an acronym for simple storage service that is hosted by Amazon Web Services (AWS) offering a reliable way to store your data. It allows storing files in buckets that are similar to folders on desktop computers and has an easy way to retrieve the data using its S3 API or browser web console.

A presigned URL allows sharing a file temporarily to users with the link or a group of users I specify. It also ensures the file is only available for a certain period of time and does not expose any of the other files in the bucket.聽

How do presigned URLs work?

Pre-signed urls work by creating a special key or token that is cryptographically unique. What that means is that it would take a really long time to guess what series of characters are in the token.

Have you ever shared a photo from Google photos and inspected the link?

You鈥檒l notice a series of seemingly random characters. Those are what make up the special key to the data. Anyone with the key is able to view it, and since it has plenty of random characters, it would be nearly impossible for someone to guess it.

In a similar way, presigned URLs include a token that grants specific individuals or services access to files.

Here鈥檚 what a presigned URL looks like:

Looking closer at the link you鈥檒l see a 鈥?鈥 and then a number of things separated by 鈥=鈥 and 鈥&鈥. Anything after the 鈥?鈥 are called url params. Each param is separated by an 鈥&.鈥 On the left side of the 鈥=鈥 is the name for the param and on the right is the value.

In the above pre-signed url we have the params 鈥淴-Amz-Algorithm鈥, 鈥淴-Amz-Credential鈥, 鈥淴-Amz-Date鈥, 鈥淴-Amz-Expires鈥, 鈥淴-Amz-SignedHeaders鈥, and 鈥淴-Amz-Signature鈥. Each param provides information to Amazon鈥檚 servers to know how to handle the link. The token (or secret key mentioned earlier) is sent with the 鈥淴-Amz-Credential鈥 param.

All right, now that we鈥檝e covered how they work, how can I use them?

How to set up 不良研究所 with aws-cli

First I鈥檒l need to download and install the aws-cli.

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

For other platforms, see .

Next I want to use the aws-cli to create a pre-signed url with 不良研究所. 不良研究所 provides an S3 compatible API which means it鈥檒l mimic what AWS would do.

Here鈥檚 how to get started:

  • on 不良研究所 DCS
  • Click 鈥淎ccess鈥 on the left navigation
  • Click 鈥淐reate S3 Credentials鈥 on the access management page
  • Give the credentials a name, permissions, and generate a passphrase for your data.



In your terminal run:

aws configure


Copy the 鈥淎ccess Key鈥 to 鈥淎WS Access Key ID鈥


Copy the 鈥淪ecret Key鈥 to 鈥淎WS Secret Access Key鈥


Finish the configuration by entering a region name and output format (default of 鈥淣one鈥 is okay).

Default region name [us-1]: us-1
Default output format [None]:聽


Upload a file to share

Now that aws-cli is configured, we鈥檒l want to create a bucket and upload a file.

To create a bucket, I鈥檒l use the 鈥渁ws mb鈥 command which takes a path to file as an argument. Much like how I visit a website on the internet with 鈥渉ttp://鈥, I can retrieve files on S3 with aws-cli using 鈥渟3://鈥 Also notice that in order to use the 不良研究所 S3 gateway, I鈥檒l need to pass the additional argument 鈥--endpoint-url=https://gateway.storjshare.io鈥.

Create a bucket called 鈥渄emo-bucket鈥

aws s3 --endpoint-url=https://gateway.storjshare.io mb s3://demo-bucket


Create a file to upload

echo "Hello this is my file" > my-file.txt


Use the 鈥渃p鈥 command to upload the file to my bucket

aws s3 --endpoint-url=https://gateway.storjshare.io cp my-file.txt s3://demo-bucket/my-file.txt


How to create presigned urls

Once you have your aws-cli configured you can proceed to generate presigned URLs with 鈥渁ws s3 presign鈥 command.

aws s3 --endpoint-url=https://gateway.storjshare.io presign s3://demo-bucket/my-file.txt


The output of this will be:

Note that the "X-Amz-Expires" header is set to the default expire time of 3600 seconds or 1 hour. By the time you鈥檙e reading this, the link will likely be expired, proving that presigned URLs work as intended.

Changing the expire time

The `aws s3 presign` command also has an option to set a custom lifetime or a specific expire time using the `--expires-in`

The following presign command generates a pre-signed URL for a specified bucket and key that is valid for one week:

aws s3 --endpoint-url=https://gateway.storjshare.io presign --expires-in 604800 s3://demo-bucket/my-file.txt



Presigned URLs are a great way to give limited access to the contents of a file. You can create them for a specific file or for all the files in a bucket. The person who receives the pre-signed URL can then access the files according to the permissions I specify.聽

Share this blog post

Put 不良研究所 to the test.

It鈥檚 simple to set up and start using 不良研究所. Sign up now to get 25GB free for 30 days.
Start your trial
product guide