DescribeInstances returns empty results

扶醉桌前 提交于 2021-01-28 08:40:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!