AWS News Blog

Now Available: Version 1.0 of the AWS SDK for Go

Earlier this year, my colleague Peter Moon shared our plans to launch an AWS SDK for Go. As you will read in Peter’s guest post below, the SDK is now generally available!

— Jeff;


At AWS, we work hard to promote and serve the developer community around our products. This is one of the reasons we open-source many of our libraries and tools on GitHub, where we cherish the ability to directly communicate and collaborate with our developer customers. Of all the experiences we’ve had in the open source community, the story of how the AWS SDK for Go came about is one we particularly love to share.

Since the day we took ownership of the project 10 months ago, community feedback and contributions have made it possible for us progress through the experimental and preview stages, and today we are excited to announce that the AWS SDK for Go is now at version 1.0 and recommended for production use. Like many of our projects, the SDK follows Semantic Versioning, which means starting from 1.0, you can upgrade the SDK within the same major version 1.x and have confidence your existing code will continue to work.

Since the Developer Preview announcement in June, we have added a number of key improvements to the SDK, including:

  • Sessions – Easily share configuration and request handlers between clients.
  • JMESPATH support – Query and reshape complex API responses and other structures using simple expressions.
  • Paginators – Iterate over multiple pages of list-type API responses.
  • Waiters – Wait for asynchronous state changes in AWS resources.
  • Documentation – Revamped developer guide.

Here’s a code sample that exercises some of these new features:

// Create a session
s := session.New(aws.NewConfig().WithRegion("us-west-2"))
// Add a handler to print every API request for the session
s.Handlers.Send.PushFront(func(r *request.Request) {
	fmt.Printf("Request: %s/%s\n", r.ClientInfo.ServiceName, r.Operation)
})
// We want to start all instances in a VPC, so let's get their IDs first.
ec2client := ec2.New(s)
var instanceIDsToStart []*string
describeInstancesInput := &ec2.DescribeInstancesInput{
	Filters: []*ec2.Filter{
		&ec2.Filter{
			Name:   aws.String("vpc-id"),
			Values: aws.StringSlice([]string{"vpc-82977de9"}),
		},
	},
}
// Use a paginator to easily iterate over multiple pages of response
ec2client.DescribeInstancesPages(describeInstancesInput,
	func(page *ec2.DescribeInstancesOutput, lastPage bool) bool {
		// Use JMESPath expressions to query complex structures
		ids, _ := awsutil.ValuesAtPath(page, "Reservations[].Instances[].InstanceId")
		for _, id := range ids {
			instanceIDsToStart = append(instanceIDsToStart, id.(*string))
		}
		return !lastPage
	})
// The SDK provides several utility functions for literal <--> pointer transformation
fmt.Println("Starting:", aws.StringValueSlice(instanceIDsToStart))
// Skipped for brevity here, but *always* handle errors in the real world :)
ec2client.StartInstances(&ec2.StartInstancesInput{
	InstanceIds: instanceIDsToStart,
})
// Finally, use a waiter function to wait until the instances are running
ec2client.WaitUntilInstanceRunning(describeInstancesInput)
fmt.Println("Instances are now running.") 

We would like to again thank Coda Hale and our friends at Stripe for contributing the original code base and giving us a wonderful starting point for the AWS SDK for Go. Now that it is fully production-ready, we can’t wait to see all the innovative applications our customers will build with the SDK!

For more information please see:

Peter Moon, Senior Product Manager