_, err := svc.GetObject(&s3.GetObjectInput{ Bucket: aws.String(bucket), Key: aws.String(key), }) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case s3.ErrCodeNoSuchBucket: fmt.Println(s3.ErrCodeNoSuchBucket, aerr.Error()) case s3.ErrCodeNoSuchKey: fmt.Println(s3.ErrCodeNoSuchKey, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } }
if _, err := s3.New(sess).ListBuckets(&s3.ListBucketsInput{}); err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case "InvalidAccessKeyId": fmt.Println("InvalidAccessKeyId") case "ExpiredToken": fmt.Println("ExpiredToken") default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } }In this example, `ListBuckets` is a method call to list all S3 buckets in the AWS SDK for Go. The `err` variable checks any errors with the request. If there is an `awserr.Error`, it will print a specific error message based on the AWS error code. Overall, the `github.com/aws/aws-sdk-go/aws/request` package library provides useful error handling features for AWS requests in the AWS SDK for Go.