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

Adding support of versionId in s3:SelectObjectContent(short issue description) #2585

Closed
1 of 2 tasks
mappie-grofers opened this issue Mar 28, 2024 · 5 comments
Closed
1 of 2 tasks
Labels
feature-request A feature should be added or improved. service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@mappie-grofers
Copy link

Describe the feature

Ideally select object content should be similar to getObject except it does select on conent. Currently it lacks VersionId support in params.
There is a way to specify version id in s3 select as per this github issue: aws/aws-sdk-java#2357 (comment)

Use Case

We only want to fetch the required content hence using selectObjectContent. But due to this we are not able to select content from older versions. Please add VersionId support in SelectObjectContent

Proposed Solution

Adding support of versionId as it is in GetObject

Other Information

There is a way to specify version id in s3 select as per this github issue: aws/aws-sdk-java#2357 (comment)

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS Go SDK V2 Module Versions Used

github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2

Go version used

1.21

@mappie-grofers mappie-grofers added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Mar 28, 2024
@lucix-aws
Copy link
Contributor

@mappie-grofers --

Based on the Java issue you've provided, the way this is done in the Java SDK is actually through generic HTTP request manipulation. This same level of customization is possible in the Go V2 SDK as well through middleware.

The following example demonstrates how to do this:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/s3"
	"github.com/aws/smithy-go/middleware"
	smithyhttp "github.com/aws/smithy-go/transport/http"
)

type withQueryParam struct {
	key, value string
}

var _ middleware.SerializeMiddleware = (*withQueryParam)(nil)

func (*withQueryParam) ID() string { return "withQueryParam" }

func (m *withQueryParam) HandleSerialize(
	ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler,
) (
	out middleware.SerializeOutput, md middleware.Metadata, err error,
) {
	req, ok := in.Request.(*smithyhttp.Request)
	if !ok {
		return out, md, fmt.Errorf("unexpected transport %T", in.Request)
	}

	// smithyhttp.Request embeds http.Request
	req.URL.RawQuery = fmt.Sprintf("%s&%s=%s", req.URL.RawQuery, m.key, m.value)
	return next.HandleSerialize(ctx, in)
}

// you don't _need_ to have this but it makes adding the middleware to multiple
// operations much easier
func addWithQueryParam(key, value string) func(*s3.Options) {
	return func(o *s3.Options) {
		o.APIOptions = append(o.APIOptions, func(s *middleware.Stack) error {
			return s.Serialize.Add(&withQueryParam{key, value}, middleware.After)
		})
	}
}

func main() {
	cfg, err := config.LoadDefaultConfig(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	svc := s3.NewFromConfig(cfg, func(o *s3.Options) {
		o.ClientLogMode = aws.LogRequest
	})

	svc.GetObject(context.Background(), &s3.GetObjectInput{
		Bucket: aws.String("bucket"),
		Key:    aws.String("key"),
	}, addWithQueryParam("foo", "bar"))
}

This is just with GetObject as an example, you can apply this to any S3 operation using functional options like I've done here.

Please try that and let us know if it works for you.

@lucix-aws lucix-aws added service-api This issue is due to a problem in a service API, not the SDK implementation. closing-soon This issue will automatically close in 4 days unless further comments are made. and removed needs-triage This issue or PR still needs to be triaged. labels Mar 28, 2024
@lucix-aws
Copy link
Contributor

lucix-aws commented Mar 28, 2024

Aside: if this is something the S3 API can do, it should really be part of their API model such that all SDKs pick it up automatically, at which point it would be a field in the request input like any other parameter. Unsure why that's not the case.

Tracking internally: V1320702086

@lucix-aws lucix-aws removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Mar 28, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

@lucix-aws
Copy link
Contributor

S3 select has acknowledged this and created a backlog item to address the modeling defect.

@mappie-grofers
Copy link
Author

mappie-grofers commented Apr 11, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

2 participants