Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions content/en/user-guide/integrations/testcontainers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ await localStackContainer.StartAsync()
.ConfigureAwait(false);
{{< /tab >}}
{{< tab header="Go" lang="go">}}
container, err := localstack.StartContainer(ctx, localstack.NoopOverrideContainerRequest)
container, err := localstack.Run(ctx, "localstack/localstack:latest")
{{< /tab >}}
{{< tab header="Java" lang="java">}}
LocalStackContainer localstack = new LocalStackContainer(DockerImageName.parse("localstack/localstack:3"));
Expand All @@ -77,42 +77,44 @@ config.ServiceURL = localStackContainer.GetConnectionString();
using var client = new AmazonS3Client(config);
{{< /tab >}}
{{< tab header="Go" lang="go">}}
type resolverV2 struct {
// you could inject additional application context here as well
}

func (*resolverV2) ResolveEndpoint(ctx context.Context, params s3.EndpointParameters) (smithyendpoints.Endpoint, error) {
// delegate back to the default v2 resolver otherwise
return s3.NewDefaultEndpointResolverV2().ResolveEndpoint(ctx, params)
}

func s3Client(ctx context.Context, l *localstack.LocalStackContainer) (*s3.Client, error) {
// the Testcontainers Docker provider is used to get the host of the Docker daemon
provider, err := testcontainers.NewDockerProvider()
mappedPort, err := l.MappedPort(ctx, nat.Port("4566/tcp"))
if err != nil {
return nil, err
}

host, err := provider.DaemonHost(ctx)
provider, err := testcontainers.NewDockerProvider()
if err != nil {
return nil, err
}
defer provider.Close()

mappedPort, err := l.MappedPort(ctx, nat.Port("4566/tcp"))
host, err := provider.DaemonHost(ctx)
if err != nil {
return nil, err
}

customResolver := aws.EndpointResolverWithOptionsFunc(
func(service, region string, opts ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{
PartitionID: "aws",
URL: fmt.Sprintf("http://%s:%d", host, mappedPort.Int()),
SigningRegion: region,
}, nil
})

awsCfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion(region),
config.WithEndpointResolverWithOptions(customResolver),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accesskey, secretkey, token)),
)
if err != nil {
return nil, err
}

// reference: https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/endpoints/#with-both
client := s3.NewFromConfig(awsCfg, func(o *s3.Options) {
o.BaseEndpoint = aws.String("http://" + host + ":" + mappedPort.Port())
o.EndpointResolverV2 = &resolverV2{}
o.UsePathStyle = true
})

Expand Down