Created
September 14, 2017 21:03
-
-
Save prl900/ec016c6ab68031060bafef6214ef5129 to your computer and use it in GitHub Desktop.
AWS Go SDK example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/awserr" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/s3" | |
) | |
func main() { | |
svc := s3.New(session.New()) | |
input := &s3.ListObjectsInput{ | |
Bucket: aws.String("eox-s2maps"), | |
MaxKeys: aws.Int64(2), | |
RequestPayer: aws.String("requester"), | |
} | |
result, err := svc.ListObjects(input) | |
if err != nil { | |
if aerr, ok := err.(awserr.Error); ok { | |
switch aerr.Code() { | |
case s3.ErrCodeNoSuchBucket: | |
fmt.Println(s3.ErrCodeNoSuchBucket, aerr.Error()) | |
default: | |
fmt.Println(aerr.Error()) | |
} | |
} else { | |
// Print the error, cast err to awserr.Error to get the Code and | |
// Message from an error. | |
fmt.Println(err.Error()) | |
} | |
return | |
} | |
fmt.Println(result) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment