Giter Club home page Giter Club logo

Comments (5)

lucix-aws avatar lucix-aws commented on June 28, 2024 1

@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.

from aws-sdk-go-v2.

lucix-aws avatar lucix-aws commented on June 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

from aws-sdk-go-v2.

github-actions avatar github-actions commented on June 28, 2024

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.

from aws-sdk-go-v2.

lucix-aws avatar lucix-aws commented on June 28, 2024

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

from aws-sdk-go-v2.

mappie-grofers avatar mappie-grofers commented on June 28, 2024

from aws-sdk-go-v2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.