How to use the Go AWS SDK with LocalStack.


The AWS SDK for Go, like other AWS SDKs, lets you set the endpoint when creating resource clients, which is the preferred way of integrating the Go SDK with LocalStack.

The Go SDK has two major versions, each with their own way of specifying the LocalStack endpoint:


Here is an example of how to create an S3 Client from a Session with the endpoint set to LocalStack. Full examples for both SDK versions can be found in our samples repository.

package main

import (

func main() {
  // Initialize a session
  sess, _ := session.NewSession(&aws.Config{
    Region:           aws.String("us-east-1"),
    Credentials:      credentials.NewStaticCredentials("test", "test", ""),
    S3ForcePathStyle: aws.Bool(true),
    Endpoint:         aws.String("http://localhost:4566"),

  // Create S3 service client
  client := s3.New(sess)

  // ...
package main

import (


func main() {
  awsEndpoint := "http://localhost:4566"
  awsRegion := "us-east-1"
  customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
    if awsEndpoint != "" {
      return aws.Endpoint{
        PartitionID:   "aws",
        URL:           awsEndpoint,
        SigningRegion: awsRegion,
      }, nil

    // returning EndpointNotFoundError will allow the service to fallback to its default resolution
    return aws.Endpoint{}, &aws.EndpointNotFoundError{}
  awsCfg, err := config.LoadDefaultConfig(context.TODO(),
  if err != nil {
    log.Fatalf("Cannot load the AWS configs: %s", err)

  // Create the resource client
  client := s3.NewFromConfig(awsCfg, func(o *s3.Options) {
    o.UsePathStyle = true
  // ...