aws-sdk-go-v2 icon indicating copy to clipboard operation
aws-sdk-go-v2 copied to clipboard

PresignedPostObject doesn't map bucket name in URL

Open rdmdb opened this issue 1 year ago • 1 comments

Acknowledgements

  • [X] I have searched (https://github.com/aws/aws-sdk/issues?q=is%3Aissue) for past instances of this issue
  • [X] I have verified all of my SDK modules are up-to-date (you can perform a bulk update with go get -u github.com/aws/aws-sdk-go-v2/...)

Describe the bug

Generating presigned URLs with PresignPostObject while using a custom BaseEndPoint and UsePathStyle set to true in the s3 config options, returns a URL that does not include the provided bucket name. This issue appears related to a similar bug in the JS counter part https://github.com/aws/aws-sdk-js-v3/commit/5054ba5fd8622960b699dfeb91a4b06dd77f5a70#diff-7253082da28c79a9309bc2a05179a34663053b1901d8724ed7f12751d5ae7ae6R90.

Regression Issue

  • [ ] Select this option if this issue appears to be a regression.

Expected Behavior

The returned URL should look like <schema>://<baseendpoint>/<bucket>

Current Behavior

The returned URL is currently formatted as <schema>://<baseendpoint>

Reproduction Steps

package main

import (
	"context"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/credentials"
	"github.com/aws/aws-sdk-go-v2/service/s3"
	"time"
)

func main() {
	staticProvider := credentials.NewStaticCredentialsProvider(
		"someAccessKey",
		"someSecret",
		"",
	)
	cfg, _ := config.LoadDefaultConfig(
		context.Background(),
		config.WithCredentialsProvider(staticProvider),
		config.WithRegion("auto"),
	)
	client := s3.NewFromConfig(cfg, func(options *s3.Options) {
		options.BaseEndpoint = aws.String("https://localhost:9000")
		options.UsePathStyle = true
	})
	presignClient := s3.NewPresignClient(client)
	request, _ := presignClient.PresignPostObject(
		context.Background(),
		&s3.PutObjectInput{
			Bucket: aws.String("mybucket"),
			Key:    aws.String("myobject"),
		}, func(opts *s3.PresignPostOptions) {
			opts.Expires = time.Duration(60) * time.Second
		},
	)
	fmt.Println(request.URL) // prints https://localhost:9000
}

Possible Solution

No response

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

module s3issue

go 1.23.1

require (
	github.com/aws/aws-sdk-go-v2 v1.32.1
	github.com/aws/aws-sdk-go-v2/config v1.27.42
	github.com/aws/aws-sdk-go-v2/credentials v1.17.40
	github.com/aws/aws-sdk-go-v2/service/s3 v1.65.1
)

require (
	github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 // indirect
	github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.16 // indirect
	github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.20 // indirect
	github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.20 // indirect
	github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
	github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.20 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.1 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.1 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.1 // indirect
	github.com/aws/aws-sdk-go-v2/service/sso v1.24.1 // indirect
	github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.1 // indirect
	github.com/aws/aws-sdk-go-v2/service/sts v1.32.1 // indirect
	github.com/aws/smithy-go v1.22.0 // indirect
)

Compiler and Version used

go version go1.23.1 darwin/arm64

Operating System and version

macOS Sequoia Version 15.0.1

rdmdb avatar Oct 08 '24 13:10 rdmdb

Hi @rdmdb ,

I'm able to reproduce the behavior. This does seem like a bug in the implementation.

I'll add to our backlog.

Thanks, Ran~

RanVaknin avatar Oct 08 '24 20:10 RanVaknin

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.

github-actions[bot] avatar Oct 25 '24 15:10 github-actions[bot]