How do I authenticate with SDK credentials on AWS using Go?

aws, go, sdk credentials, authentication, amazon web services
This guide demonstrates how to authenticate with AWS using SDK credentials in Go programming language.

package main

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

func main() {
    // Create a new session using SDK credentials
    sess, err := session.NewSession(&aws.Config{
        Region: aws.String("us-west-2")},
    )

    if err != nil {
        fmt.Println("Error creating session:", err)
        return
    }

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

    // Example: List S3 buckets
    result, err := svc.ListBuckets(nil)
    if err != nil {
        fmt.Println("Error listing buckets:", err)
        return
    }

    // Print bucket names
    fmt.Println("Buckets:")
    for _, b := range result.Buckets {
        fmt.Printf("* %s\n", aws.StringValue(b.Name))
    }
}
    

aws go sdk credentials authentication amazon web services