Convert Figma logo to code with AI

aws logoaws-sdk-go-v2

AWS SDK for the Go programming language.

2,573
620
2,573
53

Top Related Projects

AWS SDK for the Go programming language.

AWS SDK for JavaScript in the browser and Node.js

8,942

AWS SDK for Python

11,501

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code

20,922

Pulumi - Infrastructure as Code in any programming language 🚀

42,146

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.

Quick Overview

The aws/aws-sdk-go-v2 repository contains the official AWS SDK for the Go programming language (version 2). It provides a comprehensive set of tools and libraries for interacting with various AWS services, allowing developers to easily integrate AWS functionality into their Go applications.

Pros

  • Improved performance and reduced memory usage compared to v1
  • Modular architecture, allowing for smaller binary sizes
  • Enhanced support for API pagination and automatic retries
  • Consistent error handling across all AWS services

Cons

  • Breaking changes when migrating from v1 to v2
  • Steeper learning curve for newcomers due to more complex architecture
  • Some services may not have full feature parity with other AWS SDKs
  • Documentation can be overwhelming due to the large number of services covered

Code Examples

  1. Creating an S3 client and listing buckets:
import (
    "context"
    "fmt"
    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/s3"
)

func listBuckets() {
    cfg, err := config.LoadDefaultConfig(context.TODO())
    if err != nil {
        panic("Failed to load configuration")
    }

    client := s3.NewFromConfig(cfg)
    result, err := client.ListBuckets(context.TODO(), &s3.ListBucketsInput{})
    if err != nil {
        panic("Failed to list buckets")
    }

    for _, bucket := range result.Buckets {
        fmt.Println(*bucket.Name)
    }
}
  1. Sending a message to an SQS queue:
import (
    "context"
    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/sqs"
)

func sendMessage(queueURL, message string) {
    cfg, err := config.LoadDefaultConfig(context.TODO())
    if err != nil {
        panic("Failed to load configuration")
    }

    client := sqs.NewFromConfig(cfg)
    _, err = client.SendMessage(context.TODO(), &sqs.SendMessageInput{
        QueueUrl:    &queueURL,
        MessageBody: &message,
    })
    if err != nil {
        panic("Failed to send message")
    }
}
  1. Describing EC2 instances:
import (
    "context"
    "fmt"
    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/ec2"
)

func describeInstances() {
    cfg, err := config.LoadDefaultConfig(context.TODO())
    if err != nil {
        panic("Failed to load configuration")
    }

    client := ec2.NewFromConfig(cfg)
    result, err := client.DescribeInstances(context.TODO(), &ec2.DescribeInstancesInput{})
    if err != nil {
        panic("Failed to describe instances")
    }

    for _, reservation := range result.Reservations {
        for _, instance := range reservation.Instances {
            fmt.Printf("Instance ID: %s, State: %s\n", *instance.InstanceId, instance.State.Name)
        }
    }
}

Getting Started

To start using aws-sdk-go-v2, follow these steps:

  1. Install the SDK:

    go get github.com/aws/aws-sdk-go-v2
    
  2. Import the necessary packages in your Go code:

    import (
        "github.com/aws/aws-sdk-go-v2/config"
        "github.com/aws/aws-sdk-go-v2/service/s3"
    )
    
  3. Load the AWS configuration:

    cfg, err := config.LoadDefaultConfig(context.TODO())
    if err != nil {
        // Handle error
    }
    

4

Competitor Comparisons

AWS SDK for the Go programming language.

Pros of aws-sdk-go

  • More mature and stable, with a longer history of development and use
  • Wider adoption and community support
  • Simpler API design for basic use cases

Cons of aws-sdk-go

  • Larger memory footprint and slower performance in some scenarios
  • Less modular structure, making it harder to use only specific services
  • Lacks some modern Go idioms and patterns

Code Comparison

aws-sdk-go:

svc := s3.New(session.New())
input := &s3.ListObjectsInput{
    Bucket: aws.String("my-bucket"),
}
result, err := svc.ListObjects(input)

aws-sdk-go-v2:

cfg, err := config.LoadDefaultConfig(context.TODO())
client := s3.NewFromConfig(cfg)
input := &s3.ListObjectsInput{
    Bucket: aws.String("my-bucket"),
}
result, err := client.ListObjects(context.TODO(), input)

The main differences in the code are:

  1. aws-sdk-go-v2 uses a context-aware API
  2. Configuration loading is more explicit in v2
  3. Client initialization is slightly different between versions

Overall, aws-sdk-go-v2 offers improved modularity, better performance, and more idiomatic Go code, while aws-sdk-go provides stability and wider adoption. The choice between them depends on specific project requirements and preferences.

AWS SDK for JavaScript in the browser and Node.js

Pros of aws-sdk-js

  • Wider ecosystem and community support in the JavaScript/Node.js environment
  • Easier integration with web applications and serverless functions
  • More flexible and dynamic due to JavaScript's nature

Cons of aws-sdk-js

  • Generally slower performance compared to compiled languages like Go
  • Lack of static typing can lead to runtime errors
  • Larger package size and potential for dependency conflicts

Code Comparison

aws-sdk-js:

const AWS = require('aws-sdk');
const s3 = new AWS.S3();

s3.getObject({ Bucket: 'myBucket', Key: 'myKey' }, (err, data) => {
  if (err) console.log(err);
  else console.log(data.Body.toString());
});

aws-sdk-go-v2:

import (
    "github.com/aws/aws-sdk-go-v2/aws"
    "github.com/aws/aws-sdk-go-v2/service/s3"
)

client := s3.NewFromConfig(cfg)
result, err := client.GetObject(context.TODO(), &s3.GetObjectInput{
    Bucket: aws.String("myBucket"),
    Key:    aws.String("myKey"),
})

The JavaScript version is more concise but lacks type safety. The Go version is more verbose but provides stronger typing and compile-time checks. Both SDKs offer similar functionality, but the choice between them often depends on the project's language requirements and performance needs.

8,942

AWS SDK for Python

Pros of boto3

  • Extensive Python ecosystem integration and support
  • Comprehensive documentation and large community
  • High-level abstractions for easier AWS service interactions

Cons of boto3

  • Limited to Python, not suitable for Go-based projects
  • Can be slower than lower-level SDKs in some scenarios
  • Occasional version compatibility issues with AWS services

Code Comparison

boto3 (Python):

import boto3

s3 = boto3.client('s3')
response = s3.list_buckets()
for bucket in response['Buckets']:
    print(f'Bucket Name: {bucket["Name"]}')

aws-sdk-go-v2 (Go):

import (
    "context"
    "fmt"
    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/s3"
)

cfg, err := config.LoadDefaultConfig(context.TODO())
client := s3.NewFromConfig(cfg)
result, err := client.ListBuckets(context.TODO(), &s3.ListBucketsInput{})
for _, bucket := range result.Buckets {
    fmt.Printf("Bucket Name: %s\n", *bucket.Name)
}

Both SDKs provide similar functionality, but aws-sdk-go-v2 offers stronger typing and is more idiomatic for Go developers. boto3 benefits from Python's simplicity and extensive AWS community support, while aws-sdk-go-v2 leverages Go's performance and concurrency features. The choice between them often depends on the project's language requirements and specific use cases.

11,501

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code

Pros of CDK

  • Higher-level abstractions for infrastructure as code, simplifying AWS resource management
  • Multi-language support (TypeScript, Python, Java, C#)
  • Built-in best practices and patterns for AWS infrastructure

Cons of CDK

  • Steeper learning curve for developers new to infrastructure as code concepts
  • Less fine-grained control compared to direct SDK usage
  • Potential for generated CloudFormation templates to be complex and harder to debug

Code Comparison

CDK (TypeScript):

import * as cdk from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';

const bucket = new s3.Bucket(this, 'MyBucket', {
  versioned: true,
});

aws-sdk-go-v2 (Go):

import (
    "github.com/aws/aws-sdk-go-v2/aws"
    "github.com/aws/aws-sdk-go-v2/service/s3"
)

_, err := client.CreateBucket(context.TODO(), &s3.CreateBucketInput{
    Bucket: aws.String("my-bucket"),
})

The CDK example demonstrates a higher-level abstraction for creating an S3 bucket, while the aws-sdk-go-v2 example shows a more direct, low-level API call. CDK handles additional configuration and best practices automatically, whereas the SDK requires more explicit management of AWS resources.

20,922

Pulumi - Infrastructure as Code in any programming language 🚀

Pros of Pulumi

  • Multi-language support (Go, Python, TypeScript, etc.) for infrastructure as code
  • Provides a higher-level abstraction for cloud resource management
  • Offers state management and drift detection capabilities

Cons of Pulumi

  • Steeper learning curve for those familiar with traditional IaC tools
  • Requires runtime dependencies and language-specific SDKs

Code Comparison

Pulumi (TypeScript):

import * as aws from "@pulumi/aws";

const bucket = new aws.s3.Bucket("my-bucket", {
    website: { indexDocument: "index.html" },
});

AWS SDK Go v2:

import (
    "github.com/aws/aws-sdk-go-v2/service/s3"
)

input := &s3.CreateBucketInput{
    Bucket: aws.String("my-bucket"),
}
_, err := client.CreateBucket(context.TODO(), input)

Key Differences

  • Pulumi provides a declarative approach to infrastructure management, while AWS SDK Go v2 offers direct API access
  • Pulumi abstracts away many low-level details, making it easier to manage complex infrastructure
  • AWS SDK Go v2 provides more fine-grained control over AWS resources and operations

Use Cases

  • Pulumi: Ideal for teams managing multi-cloud infrastructure or seeking a unified IaC approach
  • AWS SDK Go v2: Better suited for applications requiring direct AWS service interactions or custom AWS resource management
42,146

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.

Pros of Terraform

  • Broader scope: Manages infrastructure across multiple cloud providers and services
  • Declarative approach: Defines desired state, simplifying infrastructure management
  • Large ecosystem: Extensive provider and module library for various resources

Cons of Terraform

  • Steeper learning curve: Requires understanding HCL and infrastructure concepts
  • Less AWS-specific functionality: May not cover all AWS features as comprehensively
  • Potential for state management complexity in large-scale deployments

Code Comparison

Terraform (HCL):

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
}

AWS SDK Go v2 (Go):

input := &ec2.RunInstancesInput{
    ImageId:      aws.String("ami-0c55b159cbfafe1f0"),
    InstanceType: ec2.InstanceTypeT2Micro,
    MinCount:     aws.Int32(1),
    MaxCount:     aws.Int32(1),
}

Summary

Terraform is a multi-cloud infrastructure management tool with a declarative approach, while AWS SDK Go v2 is a programmatic interface for AWS services. Terraform excels in managing infrastructure across providers, but has a steeper learning curve. AWS SDK Go v2 offers more fine-grained control over AWS resources but requires more code for infrastructure management. Choose based on your specific needs: cross-cloud management (Terraform) or AWS-specific programmatic control (AWS SDK Go v2).

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

AWS SDK for Go v2

Go Build statusCodegen Build status SDK Documentation Migration Guide API Reference Apache V2 License

aws-sdk-go-v2 is the v2 AWS SDK for the Go programming language.

The v2 SDK requires a minimum version of Go 1.21.

Check out the release notes for information about the latest bug fixes, updates, and features added to the SDK.

Jump To:

Maintenance and support for SDK major versions

For information about maintenance and support for SDK major versions and their underlying dependencies, see the following in the AWS SDKs and Tools Shared Configuration and Credentials Reference Guide:

Go version support policy

The v2 SDK follows the upstream release policy with an additional six months of support for the most recently deprecated language version.

AWS reserves the right to drop support for unsupported Go versions earlier to address critical security issues.

Getting started

To get started working with the SDK setup your project for Go modules, and retrieve the SDK dependencies with go get. This example shows how you can use the v2 SDK to make an API request using the SDK's Amazon DynamoDB client.

Initialize Project
$ mkdir ~/helloaws
$ cd ~/helloaws
$ go mod init helloaws
Add SDK Dependencies
$ go get github.com/aws/aws-sdk-go-v2/aws
$ go get github.com/aws/aws-sdk-go-v2/config
$ go get github.com/aws/aws-sdk-go-v2/service/dynamodb
Write Code

In your preferred editor add the following content to main.go

package main

import (
    "context"
    "fmt"
    "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/dynamodb"
)

func main() {
    // Using the SDK's default configuration, loading additional config
    // and credentials values from the environment variables, shared
    // credentials, and shared configuration files
    cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-west-2"))
    if err != nil {
        log.Fatalf("unable to load SDK config, %v", err)
    }

    // Using the Config value, create the DynamoDB client
    svc := dynamodb.NewFromConfig(cfg)

    // Build the request with its input parameters
    resp, err := svc.ListTables(context.TODO(), &dynamodb.ListTablesInput{
        Limit: aws.Int32(5),
    })
    if err != nil {
        log.Fatalf("failed to list tables, %v", err)
    }

    fmt.Println("Tables:")
    for _, tableName := range resp.TableNames {
        fmt.Println(tableName)
    }
}
Compile and Execute
$ go run .
Tables:
tableOne
tableTwo

Getting Help

Please use these community resources for getting help. We use the GitHub issues for tracking bugs and feature requests.

This SDK implements AWS service APIs. For general issues regarding the AWS services and their limitations, you may also take a look at the Amazon Web Services Discussion Forums.

Opening Issues

If you encounter a bug with the AWS SDK for Go we would like to hear about it. Search the existing issues and see if others are also experiencing the same issue before opening a new issue. Please include the version of AWS SDK for Go, Go language, and OS you’re using. Please also include reproduction case when appropriate.

The GitHub issues are intended for bug reports and feature requests. For help and questions with using AWS SDK for Go please make use of the resources listed in the Getting Help section. Keeping the list of open issues lean will help us respond in a timely manner.

Feedback and contributing

The v2 SDK will use GitHub Issues to track feature requests and issues with the SDK. In addition, we'll use GitHub Projects to track large tasks spanning multiple pull requests, such as refactoring the SDK's internal request lifecycle. You can provide feedback to us in several ways.

GitHub issues. To provide feedback or report bugs, file GitHub Issues on the SDK. This is the preferred mechanism to give feedback so that other users can engage in the conversation, +1 issues, etc. Issues you open will be evaluated, and included in our roadmap for the GA launch.

Contributing. You can open pull requests for fixes or additions to the AWS SDK for Go 2.0. All pull requests must be submitted under the Apache 2.0 license and will be reviewed by an SDK team member before being merged in. Accompanying unit tests, where possible, are appreciated.

Resources

SDK Developer Guide - Use this document to learn how to get started and use the AWS SDK for Go V2.

SDK Migration Guide - Use this document to learn how to migrate to V2 from the AWS SDK for Go.

SDK API Reference Documentation - Use this document to look up all API operation input and output parameters for AWS services supported by the SDK. The API reference also includes documentation of the SDK, and examples how to using the SDK, service client API operations, and API operation require parameters.

Service Documentation - Use this documentation to learn how to interface with AWS services. These guides are great for getting started with a service, or when looking for more information about a service. While this document is not required for coding, services may supply helpful samples to look out for.

Forum - Ask questions, get help, and give feedback

Issues - Report issues, submit pull requests, and get involved (see Apache 2.0 License)