Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

paginate ec2 instances #416

Merged
merged 1 commit into from
Oct 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions resources/ec2-instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,29 @@ func init() {

func ListEC2Instances(sess *session.Session) ([]Resource, error) {
svc := ec2.New(sess)

params := &ec2.DescribeInstancesInput{}
resp, err := svc.DescribeInstances(params)
if err != nil {
return nil, err
}

resources := make([]Resource, 0)
for _, reservation := range resp.Reservations {
for _, instance := range reservation.Instances {
resources = append(resources, &EC2Instance{
svc: svc,
instance: instance,
})
for {
resp, err := svc.DescribeInstances(params)
if err != nil {
return nil, err
}

for _, reservation := range resp.Reservations {
for _, instance := range reservation.Instances {
resources = append(resources, &EC2Instance{
svc: svc,
instance: instance,
})
}
}

if resp.NextToken == nil {
break
}

params = &ec2.DescribeInstancesInput{
NextToken: resp.NextToken,
}
}

Expand Down