如何索引 AWS 快照输出?

huangapple go评论69阅读模式
英文:

How to index aws snapshot output?

问题

这里是我打印我的快照。我在下面发布了我希望快照打印出来的样子,并且也希望能够打印单个快照。我不确定如何做到这一点,任何帮助都将是很好的。

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))

这是输出的内容:https://i.stack.imgur.com/VcRMB.jpg
这是我希望输出的内容:

{
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

}]
完整代码在这里:http://pastebin.com/QgmV6kRj

英文:

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: https://i.stack.imgur.com/VcRMB.jpg
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

得分: 0

如果您想打印每个快照的详细信息,可以遍历响应:

resp, err := svc.DescribeSnapshots(params)
if err != nil {
	log.Fatal(err)
}
for i, s := range resp.Snapshots {
	fmt.Printf("快照:%d\n", i)
	fmt.Println(s)
}
英文:

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\n", i)
	fmt.Println(s)
}

huangapple
  • 本文由 发表于 2015年7月22日 02:56:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/31547381.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定