From 5a26649c2f940ff3527e36e180a0e611401ca19a Mon Sep 17 00:00:00 2001 From: tenyo Date: Fri, 10 Jun 2022 16:12:03 -0400 Subject: [PATCH] Properly list attached volumes (#33) * use attachment instance-id * fixup --- ec2/instances.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ec2/instances.go b/ec2/instances.go index 0be5a5e..891348a 100644 --- a/ec2/instances.go +++ b/ec2/instances.go @@ -140,13 +140,18 @@ func (e *Ec2) ListInstanceVolumes(ctx context.Context, id string) ([]string, err return nil, apierror.New(apierror.ErrBadRequest, "invalid input", nil) } - log.Infof("getting snapshots for instance %s/%s", e.org, id) + log.Infof("getting volumes for instance %s/%s", e.org, id) volumes := []string{} input := ec2.DescribeVolumesInput{ Filters: []*ec2.Filter{ - withInstanceId(id), + { + Name: aws.String("attachment.instance-id"), + Values: aws.StringSlice( + []string{id}, + ), + }, }, MaxResults: aws.Int64(1000), } @@ -154,10 +159,10 @@ func (e *Ec2) ListInstanceVolumes(ctx context.Context, id string) ([]string, err for { out, err := e.Service.DescribeVolumesWithContext(ctx, &input) if err != nil { - return nil, common.ErrCode("describing snapshots for volumes", err) + return nil, common.ErrCode("describing volumes for instance", err) } - log.Debugf("got describe snapshots output %+v", out) + log.Debugf("got describe volumes output %+v", out) for _, v := range out.Volumes { volumes = append(volumes, aws.StringValue(v.VolumeId))