6

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?

Freid001
  • 2,580
  • 3
  • 29
  • 60

1 Answers1

13

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
})
Freid001
  • 2,580
  • 3
  • 29
  • 60
  • For those who are looking the same for JavaScript (node.js) it is: `const s3 = new S3({forcePathStyle: true});` – Kostanos Mar 28 '23 at 22:53