问题
I am using DescribeInstances api fetch all my EC2 instances . But I am not able to get any information about my instance. I can only see empty results as success. I am providing my code in steps to reproduce section.
Output I can see as below:
Success {
}
I am also exporting AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY and AWS_REGION
Below is the code Snippet
<pre> <code>
import (
"fmt"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
)
func main() {
// Load session from shared config
sess, err := session.NewSession()
// Create new EC2 client
ec2Svc := ec2.New(sess)
resp, err := ec2Svc.DescribeInstances(nil)
if err != nil {
fmt.Println("Error", err)
} else {
fmt.Println("Success", resp)
for idx, res := range resp.Reservations {
fmt.Println(" > Number of instances: ", len(res.Instances))
for _, inst := range resp.Reservations[idx].Instances {
fmt.Println(" - Instance ID: ", *inst.InstanceId)
}
}
}
}
</code></pre>
来源:https://stackoverflow.com/questions/45572817/describeinstances-returns-empty-results