How do I configure S3ForcePathStyle with AWS golang v2 SDK?
Asked Answered
J

1

8

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?

Jacklynjackman answered 10/2, 2021 at 13:16 Comment(2)
What about Config.WithS3ForcePathStyle?Undershirt
@Undershirt OP was requesting for V2. Config.WithS3ForcePathStyle is for AWS SDK V1 onlyAntipope
J
18

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
})
Jacklynjackman answered 10/2, 2021 at 16:53 Comment(1)
For those who are looking the same for JavaScript (node.js) it is: const s3 = new S3({forcePathStyle: true});Reluctant

© 2022 - 2024 — McMap. All rights reserved.