Search code examples
amazon-web-servicesgoamazon-s3aws-sdkaws-sdk-go

How do I configure S3ForcePathStyle with AWS golang v2 SDK?


I'm putting and reading files to S3 using the AWS golang v2 SDK. Locally I am using local stack and thus need to set the param S3ForcePathStyle. But, I can't find where to set this parameter in the config.

This is what my config looks like:

conf, err = config.LoadDefaultConfig(
            context.TODO(),
            config.WithRegion("us-east-1"),
            config.WithEndpointResolver(
                aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
                    return aws.Endpoint{
                        PartitionID:   "aws",
                        URL:           "http://localstack:4566",
                        SigningRegion: "us-east-1",
                    }, nil
                }),
            ),
        )

Where can I pass in S3ForcePathStyle = true?


Solution

  • Seems I was looking in the wrong place. The documentation here explains that in aws-sdk-go-v2 they moved the service-specific configuration flags to the individual service client option types. Ironically to improve discoverability.

    I should set the UsePathStyle like this:

    client := s3.NewFromConfig(conf, func(o *s3.Options) {
        o.UsePathStyle = true
    })