Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a PresignPostObject to the PresignClient for s3.PutObject operation #2758

Merged
merged 9 commits into from
Aug 28, 2024

Conversation

Madrigal
Copy link
Contributor

@Madrigal Madrigal commented Aug 22, 2024

For changes to files under the /codegen/aws-models folder, and manual edits to autogenerated code (e.g. /service/s3/api.go) please create an Issue instead of a PR for those type of changes.

If the PR addresses an existing bug or feature, please reference it here.

To help speed up the process and reduce the time to merge please ensure that Allow edits by maintainers is checked before submitting your PR. This will allow the project maintainers to make minor adjustments or improvements to the submitted PR, allow us to reduce the roundtrip time for merging your request.

This is used as follows

// conditions that you want your request to have
// see https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html#sigv4-PolicyConditions
conditions := []interface{}{
	[]interface{}{
		"content-length-range",
		1,
		10485760,
	},
}
// Duration on which you want this request to
expiresIn = 20 * time.Minute
req, err := presignClient.PresignPostObject(examplePresigner.ctx, &s3.PutObjectInput{
	Bucket: aws.String(bucketName),
	Key:    aws.String(uploadKey),
}, func(opts *s3.PresignPostOptions) {
	opts.Expires = expiresIn
	opts.Conditions = conditions
})
if err != nil {
	log.Printf("Couldn't get a presigned request to put %v:%v. Here's why: %v\n",
		bucketName, uploadKey, err)
}
fmt.Println(req.URL) 
// https://test-bucket.s3.us-west-2.amazonaws.com
fmt.Println(req.Values)
// map[X-Amz-Algorithm:AWS4-HMAC-SHA256
// X-Amz-Credential:ASIAXXXX/20240822/us-west-2/s3/aws4_request
// X-Amz-Date:20240822T215442Z
// X-Amz-Signature:d7c4f16a9a0b8d60a7ed4f01234b0f9c2e58f12d0d3a847f91f1b3e7d6f8192a
// key:my_file.json
// policy:base64encodedValue]

fixes #1224

@Madrigal Madrigal requested a review from a team as a code owner August 22, 2024 22:12
Copy link
Contributor

@lucix-aws lucix-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment, this seems worthy of an integration test if we can swing it (so like actually generate a presigned URL, form POST the object, and then download to verify).

We have a bunch of existing presign tests in service/internal/integrationtest/s3/presign_test.go

@Madrigal Madrigal merged commit 9c621d1 into main Aug 28, 2024
12 checks passed
@Madrigal Madrigal deleted the feature-presign-post branch August 28, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add convenience method for S3 presigned posts
2 participants