Publishing S3 Objects with Signed URLs
January 30, 2025The owner of an S3 bucket can share an object by creating a presigned URL for it. The AWS Documentation provides a user guide on how to generate presigned URLs.
When I tried generating a presigned URL using the document, I found that preparing the bucket and file was a bit cumbersome. Additionally, the guide doesn’t cover how to instantiate a client to generate the URL, so I had to look for another guide to learn how to do this.
I’ve researched generating presigned URLs a couple of times before and eventually implemented Terraform scripts and a Go script for future reference. The Terraform scripts create an S3 bucket and upload a file to it. The Go script generates a presigned URL for the file using the AWS SDK. These resources are available in this GitHub repository.
In the root directory of the repository, there’s a Makefile
with a run
target.
This target creates a S3 bucket, uploads an object to the bucket, and generates its signed URL
Here’s an example command:
make AWS_REGION=<aws_region> AWS_PROFILE=<profile> BUCKET_NAME=<bucket_name>
When I ran the target, I encountered an error on the first execution, but the second attempt succeeded.
It seems Terraform cannot create an S3 bucket and upload an object to it at the same time.
Eventually, the target prints a presigned URL to the standard output.
The Makefile
provides remove-aws
target that removes the stacks created by the Terraform scripts.