I am a beginner in Go and am starting to use the AWS SDK.
I want to fetch some EC2 fields by looking for a tag using DescribeInstances
. That works well.
But if I use a tag that does not exist as parameter I get an empty struct as response:
{
}
I tried to test the result with nil
and using unsafe.Sizeof()
, but I don't get nil value or 0 value.
What would be the correct way to do it?
Thanks!
edit: I found a way to check. Because the aws api is inconsistent, sometimes it returns errors sometimes it does not. So for this sparticular call I test the size of the []*ec2.Reservation that is returned:
result, err := ec2Svc.DescribeInstances(input)
if len(result.Reservations) == 0 {
fmt.Println("Nothing found for this tag")
fmt.Println(err)
} else {
for _, instance := range result.Reservations[0].Instances {
return *instance.VpcId
}
}