aws / aws-sdk-go-v2

AWS SDK for the Go programming language.
https://aws.github.io/aws-sdk-go-v2/docs/
Apache License 2.0
2.6k stars 627 forks source link

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

Closed arjendevos closed 4 months ago

arjendevos commented 4 months ago

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)

github-actions[bot] commented 4 months ago

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 commented 2 weeks ago

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