Skip to content

Instantly share code, notes, and snippets.

@lmllrjr
Last active November 28, 2023 19:20
Show Gist options
  • Save lmllrjr/84c96f1700c3ac3f1168224317864d3c to your computer and use it in GitHub Desktop.
Save lmllrjr/84c96f1700c3ac3f1168224317864d3c to your computer and use it in GitHub Desktop.
How to create a curl request using a presigned URL from an AWS S3 bucket

AWS S3 Presigned URL Example

The url that is being returned by aws s3.PresignClient:

"http://localhost:9000/bucket-name/bucket-key?
X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20231127%2Feu-west-1%2Fs3%2Faws4_request
&X-Amz-Date=20231127T163354Z
&X-Amz-Expires=900
&X-Amz-SignedHeaders=expires%3Bhost
&x-id=PutObject
&X-Amz-Signature=b187cc4d700e46a3b6e381a37a334e604cc782fe9a544051e8e411ac23316a6e"

Creating a presigned URL does also return headers that need to be included in the request. In Go i get something like the following:

map[string][]string{"Expires":[]string{"Tue, 28 Nov 2023 15:20:41 GMT"}, "Host":[]string{"localhost:9000"}}

Lastly it also returns the expected http.Method the request must have

"PUT"

Combining all of the above knowledge and create a curl request:

curl -X PUT "http://localhost:9000/bucket-name/bucket-key?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20231127%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20231127T163354Z&X-Amz-Expires=900&X-Amz-SignedHeaders=expires%3Bhost&x-id=PutObject&X-Amz-Signature=b187cc4d700e46a3b6e381a37a334e604cc782fe9a544051e8e411ac23316a6e" \
-H "Expires: Mon, 28 Nov 2023 15:20:41 GMT" \
-H "Host: localhost" \
-d "Hello, World!"

Voilà, the data was successfully put into an AWS S3 Bucket via a presigned URL.

Check if the bucket for data using aws cli:

aws s3 --endpoint-url ${AWS_S3_ENDPOINT} ls s3://bucket-name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment