amazon-web-servicesgoaws-sdklocalstack

How do I use aws-sdk-go-v2 with localstack?


I'm trying to migrate from aws-sdk-go to aws-sdk-go-v2. But, I am using localstack locally to mimic some aws services such as sqs and s3. I'm not sure how to configure the new sdk to use the localstack endpoint instead of the real one.

For example, in the v1 SDK I can point it to localstack by setting the endpoint here:

session.Must(session.NewSession(&aws.Config{
    Region:   aws.String("us-east-1"),
    Endpoint: aws.String("http://localstack:4566"), 
}))

But, how do I do this in the v2 SDK? I think I need to set some param in the config but I dont see any option to specify the endpoint.


Solution

  • It depends from the service that you use.

    In order to initialize a Glue client:

    cfg, err := config.LoadDefaultConfig(context.Background())
    if err != nil {
        panic(err)
    }
    glueConnection := glue.New(glue.Options{Credentials: cfg.Credentials, Region: cfg.Region})