普通网友 2015-07-21 18:56
浏览 38
已采纳

如何索引AWS快照输出?

Here I am printing my snapshots. I posted below what I would like the snapshot print out to look like, and would also like to be able to print individual snapshots. I am not sure how to do this any help would be great.

svc := ec2.New(&aws.Config{Region: "us-east-1"})
params := &ec2.DescribeSnapshotsInput{
    OwnerIDs: []*string{
        aws.String("130300684064"),
    },
}

b, err2 := svc.DescribeSnapshots(params)
if err2 != nil {
    panic(err2)
}
fmt.Printf(awsutil.StringValue(b))

Here is what gets outputted: http://imgur.com/3MnBNXI This is what I would like to be output:

{

Snapshots:

----0

  Description: "Snapshot from MULTI",

  Encrypted: false,

  OwnerID: "130300684064",

  Progress: "100%!"(MISSING),

  SnapshotID: "snap-81b1dff6",

  StartTime: 2015-07-21 18:41:54 +0000 UTC,

  State: "completed",

  VolumeID: "vol-5121ebaa",

  VolumeSize: 1

},{

----1

  Description: "Snapshot from MULTI",

  Encrypted: false,

  OwnerID: "130300684064",

  Progress: "100%!"(MISSING),

  SnapshotID: "snap-08352a7f",

  StartTime: 2015-07-21 18:41:54 +0000 UTC,

  State: "completed",

  VolumeID: "vol-9b21eb60",

  VolumeSize: 1

},{

----2

  Description: "Snapshot from MULTI",

  Encrypted: false,

  OwnerID: "130300684064",

  Progress: "100%!"(MISSING),

  SnapshotID: "snap-768ffb00",

  StartTime: 2015-07-21 18:41:54 +0000 UTC,

  State: "completed",

  VolumeID: "vol-5620eaad",

  VolumeSize: 1

}]

Full code here: http://pastebin.com/QgmV6kRj

  • 写回答

1条回答 默认 最新

  • doucai9270 2015-07-21 20:34
    关注

    If you want to print the details of the individual snapshots, you can iterate over the response:

    resp, err := svc.DescribeSnapshots(params)
    if err != nil {
        log.Fatal(err)
    }
    for i, s := range resp.Snapshots {
        fmt.Printf("Snapshot: %d
    ", i)
        fmt.Println(s)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Labview机器人问题
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr