Skip to content

Conversation

@Madrigal
Copy link
Contributor

This is Luis from the Go SDK team

We recently added support for s3 presign POST requests at aws/aws-sdk-go-v2#1224

We'd like to expand the existing examples to add presign post requests.

Let me know if there's anything I should change about the tags used to create the examples so they display correctly at https://docs.aws.amazon.com/AmazonS3/latest/userguide/example_s3_Scenario_PresignedUrl_section.html

This scenario has a bit more complex way of sending the request since multipart requests require more setup. However, this is mostly intended to be used by a browser sending a form rather than sending this directly from a Go server.

Tested this by

  1. Running go run ./cmd -scenario presigning and making sure it works as expected with a local file
 go run ./cmd -scenario presigning
----------------------------------------------------------------------------------------
Welcome to the Amazon S3 presigning demo.
----------------------------------------------------------------------------------------
We'll need a bucket. Enter a name for a bucket you own or one you want to create:
lmadrig-presign
Bucket lmadrig-presign exists and you already own it.
----------------------------------------------------------------------------------------
Let's presign a request to upload a file to your bucket.
Enter the path to a file you want to upload:
/Volumes/workplace/sample.txt
What would you like to name the uploaded object?
my-presign
Got a presigned PUT request to URL:
	https://lmadrig-presign.s3.us-west-2.amazonaws.com/my-presign?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAExample%2F20240927%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20240927T170511Z&X-Amz-Expires=60&X-Amz-Security-Token=XXXX&X-Amz-SignedHeaders=host&x-id=PutObject&X-Amz-Signature=YYYY
Using net/http to send the request...
PUT object my-presign with presigned URL returned 200.
----------------------------------------------------------------------------------------
Let's presign a request to download the object.
Press Enter when you're ready.

Got a presigned GET request to URL:
	https://lmadrig-presign.s3.us-west-2.amazonaws.com/my-presign?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAExample%2F20240927%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20240927T170513Z&X-Amz-Expires=60&X-Amz-Security-Token=XXXX&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=YYYY
Using net/http to send the request...
GET object my-presign with presigned URL returned 200.
Downloaded 12 bytes. Here are the first 100 of them:
----------------------------------------------------------------------------------------
Hello world

----------------------------------------------------------------------------------------
Now we'll create a new request to put the same object using a presigned post request
Got a presigned post request to url https://lmadrig-presign.s3.us-west-2.amazonaws.com with values map[X-Amz-Algorithm:AWS4-HMAC-SHA256 X-Amz-Credential:ASIAExample/20240927/us-west-2/s3/aws4_request X-Amz-Date:20240927T170513Z X-Amz-Security-Token:XXXX key:my-presign policy:base64str]
Using net/http multipart to send the request...
Presign post object my-presign with presigned URL returned 204.
Let's presign a request to delete the object.
Press Enter when you're ready.

Got a presigned DELETE request to URL:
	https://lmadrig-presign.s3.us-west-2.amazonaws.com/my-presign?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAExample%2F20240927%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20240927T170516Z&X-Amz-Expires=900&X-Amz-Security-Token=XXXX&X-Amz-SignedHeaders=host&x-id=DeleteObject&X-Amz-Signature=YYYY
Using net/http to send the request...
DELETE object my-presign with presigned URL returned 204.
----------------------------------------------------------------------------------------
Thanks for watching!
----------------------------------------------------------------------------------------
  1. Running go test inside the s3 folder
go test ./...
?   	github.com/awsdocs/aws-doc-sdk-examples/gov2/s3/cmd	[no test files]
?   	github.com/awsdocs/aws-doc-sdk-examples/gov2/s3/hello	[no test files]
?   	github.com/awsdocs/aws-doc-sdk-examples/gov2/s3/stubs	[no test files]
ok  	github.com/awsdocs/aws-doc-sdk-examples/gov2/s3/actions	(cached)
ok  	github.com/awsdocs/aws-doc-sdk-examples/gov2/s3/scenarios	(cached)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the Go-v2 This issue relates to the AWS SDK for Go V2 label Sep 27, 2024
@Laren-AWS Laren-AWS self-assigned this Sep 27, 2024
@Laren-AWS Laren-AWS self-requested a review September 27, 2024 18:47
@Laren-AWS Laren-AWS added On Call Review complete On call review complete Task A general update to the code base for language clarification, missing actions, tests, etc. labels Sep 27, 2024
@Laren-AWS Laren-AWS force-pushed the feat-gov2-add-presign-post branch from 64a7f2b to 474199a Compare September 27, 2024 21:08
@Laren-AWS Laren-AWS merged commit d8a741f into awsdocs:main Sep 27, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Go-v2 This issue relates to the AWS SDK for Go V2 On Call Review complete On call review complete Task A general update to the code base for language clarification, missing actions, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants