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

Something changed from version v1.22.2 to v1.26.1 and I can't find what #2643

Closed
2 tasks done
arjendevos opened this issue May 14, 2024 · 2 comments
Closed
2 tasks done
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@arjendevos
Copy link

Acknowledgements

Describe the bug

No bug in these versions:

github.com/aws/aws-sdk-go-v2 v1.22.2
github.com/aws/aws-sdk-go-v2/config v1.23.0
github.com/aws/aws-sdk-go-v2/credentials v1.15.2
github.com/aws/aws-sdk-go-v2/service/s3 v1.42.1

Suddenly doesn't resolve endpoint anymore in these versions:

github.com/aws/aws-sdk-go-v2 v1.26.1
github.com/aws/aws-sdk-go-v2/config v1.23.0
github.com/aws/aws-sdk-go-v2/credentials v1.15.2
github.com/aws/aws-sdk-go-v2/service/s3 v1.42.1

I have a client like this:

func NewClient() (*Client, error) {
	var (
		accessKeyId     = os.Getenv("R2_BUCKET_ACCESS_KEY_ID")
		accessKeySecret = os.Getenv("R2_BUCKET_SECRET_ACCESS_KEY")
		bucketPath      = os.Getenv("R2_BUCKET_PATH")
	)

	// Create a custom endpoint resolver
	customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
		return aws.Endpoint{
			URL: bucketPath,
		}, nil
	})

	// Load the AWS configuration with the custom endpoint resolver and credentials
	cfg, err := config.LoadDefaultConfig(context.Background(),
		config.WithEndpointResolverWithOptions(customResolver),
		config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKeyId, accessKeySecret, "")),
	)
	if err != nil {
		return nil, err
	}

	return &Client{
		Client: s3.NewFromConfig(cfg),
	}, nil
}

func (c *Client) Upload(body io.Reader, dir, filename string) (string, error) {
	var (
		env       = os.Getenv("ENV")
		bucket    = os.Getenv("R2_BUCKET")
		publicUrl = os.Getenv("R2_PUBLIC_URL")
		extension = strings.ToLower(filepath.Ext(filename))
	)

	rs, err := goutils.GenerateRandomString(32)
	if err != nil {
		return "", err
	}

	fileName := fmt.Sprintf("%v/%v%v", dir, rs, extension)
	if _, err := c.PutObject(context.Background(), &s3.PutObjectInput{
		Bucket:      aws.String(bucket),
		Key:         aws.String(fileName),
		ContentType: aws.String(gomime.TypeByExtension(extension)),
		Body:        body,
	}); err != nil {
		return "", err
	}

	return fmt.Sprint(publicUrl, "/", fileName), nil
}

Issue: not found, ResolveEndpointV2 when uploading

Expected Behavior

File should upload

Current Behavior

File does not upload, get error: not found, ResolveEndpointV2

Reproduction Steps

Code provided in bug report^

Possible Solution

No response

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

No bug in these versions:

github.com/aws/aws-sdk-go-v2 v1.22.2
github.com/aws/aws-sdk-go-v2/config v1.23.0
github.com/aws/aws-sdk-go-v2/credentials v1.15.2
github.com/aws/aws-sdk-go-v2/service/s3 v1.42.1

Suddenly doesn't resolve endpoint anymore in these versions:

github.com/aws/aws-sdk-go-v2 v1.26.1
github.com/aws/aws-sdk-go-v2/config v1.23.0
github.com/aws/aws-sdk-go-v2/credentials v1.15.2
github.com/aws/aws-sdk-go-v2/service/s3 v1.42.1

Compiler and Version used

go version go1.21.6 darwin/arm64

Operating System and version

macOS 13.6.3 (22G436)

@arjendevos arjendevos added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 14, 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.

@LeonGeorgiDevBoost
Copy link

You immediately closed this issue, but didn't describe your solution. Do you remember what it was @arjendevos?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants