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/ec2"
)
func main() {
svc := ec2.New(
session.New(),
&aws.Config{
Region: aws.String("ap-northeast-1"),
})
input := &ec2.DescribeInstancesInput{
InstanceIds: []*string{
aws.String("i-xxxxxxxxxxxxxxxx"),
},
}
result, err := svc.DescribeInstances(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
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)
}