AWS Developer Tools Blog

AWS SDK for Go version 2 (v2) – Release Candidate

As of January 19th, 2021, the AWS SDK for Go, version 2 (v2) is generally available.

We’re happy to announce the Release Candidate (RC) of the AWS SDK for Go version 2 (v2). This RC follows the developer preview release of the AWS SDK for Go v2. The SDK has undergone a major rewrite from the v1 code base to incorporate your feedback and to take advantage of modern Go language features. Some of the highlighted features of the release candidate include:

  • Modularized: Service clients and functionality are now packaged as independent Go modules, allowing you to model service dependencies in your application, and independently control service client updates.
  • Pointer Reduction: Service API parameters have been updated to reduce the number of pointers you are required to pass.
  • Paginators: Easily iterate over API results that span multiple pages.
  • Waiters: Easily validate that AWS resources are in a particular state before performing additional actions.
  • Error Wrapping: Error types have been redesigned to take advantage of error wrapping features introduced in Go 1.13.
  • Extensibility: New middleware design allows for your application to extend or customize the request pipeline to fit your use case.
  • Amazon S3 Transfer Manager: Allows easy, reliable, and efficient transfer of large files to and from Amazon S3 in multiple parts using a customizable number of goroutines.
  • Amazon DynamoDB AttributeValue and Expression Packages: Easily translate your application Go types to Amazon DynamoDB AttributeValues. Use the expression package to fluently build attribute updates and conditions.
  • Reduced Runtime Overhead: API serialization and deserialization have been optimized to remove the Go runtime reflection, improving performance by reducing overhead.

Getting Started

Let’s look at how you can get started using the AWS SDK for Go v2. First, you need to ensure you have the minimum supported Go version installed (1.15).

  1. Initialize a Go module for your example application. Here we will make a new directory, and initialize our rcdemo module. This initialization will create a go.mod file in the directory.
    $ mkdir ~/go-blog-rcdemo
    $ cd ~/go-blog-rcdemo
    $ go mod init rcdemo
  2. In your editor of choice, create a main.go file, and add the following code. This code will load default SDK configuration, and will construct an Amazon S3 client.
    package main
    
    import (
        "context"
        "log"
        "github.com/aws/aws-sdk-go-v2/aws"
        "github.com/aws/aws-sdk-go-v2/config"
        "github.com/aws/aws-sdk-go-v2/service/s3"
    )
    
    func main() {
        // Load the Shared AWS Configuration (~/.aws/config)
        config, err := config.LoadDefaultConfig(context.TODO())
        if err != nil {
            log.Fatal(err)
        }
    
        // Create an Amazon S3 service client
        client := s3.NewFromConfig(config)
    
        // Get the first page of results for ListObjectsV2 for a bucket.
        output, err := client.ListObjectsV2(context.TODO(), &s3.ListObjectsV2Input{
            Bucket: aws.String("my-bucket"),
        })
        if err != nil {
            log.Fatal(err)
        }
    
        log.Println("first page results:")
        for _, object := range output.Contents {
            log.Printf("key=%s size=%d", aws.ToString(object.Key), object.Size)
        }
    }
  3. Now run the module tidy command, which will handle downloading the referenced dependencies automatically. The dependencies will be recorded in the demo application’s go.mod file.
    $ go mod tidy
  4. Build and run the application
    $ go build -o demo .
    $ ./demo

Resources

To learn more about the AWS SDK for Go v2 Release Candidate, visit the Developer Guide or API Reference. Visit the migration guide to learn more about migrating applications from version 1 to version 2.

Next Steps

The release candidate marks a major milestone for the AWS SDK for Go v2, and represents the stable set of features we intend to make available when the SDK reaches generally available (GA) status in the future. We encourage you to provide us feedback on what you like, don’t like, or any issues you can encounter while using the release candidate. You can do so by opening an issue on GitHub.