I am importing the following go module:
import "github.com/aws/aws-sdk-go-v2/service/ec2"
I want to write a simple function that iterates over the instance tags so I am doing the following
func getInstanceDescription(instance *ec2.Instance) string {
for _, tag := range instance.Tags {
if *tag.Key == "Name" || *tag.Key == "name" {
return *tag.Value
}
}
return *instance.InstanceId
}
However, despite the fact that Instance is a type of this package, compiler complains
undefined: ec2.Instance compiler(UndeclaredImportedName)
What am I doing wrong?
You are using the
Instancestruct wrongly. As theInstancestruct is not inec2package, it is in thetypessub package.You should use as