MCPcopy Create free account
hub / github.com/barnybug/cli53 / instances

Function instances

instances.go:32–149  ·  view source on GitHub ↗
(ctx context.Context, args instancesArgs, config aws.Config)

Source from the content-addressed store, hash-verified

30}
31
32func instances(ctx context.Context, args instancesArgs, config aws.Config) {
33 zone := lookupZone(ctx, args.name)
34 fmt.Println("Getting DNS records")
35
36 describeInstancesInput := ec2.DescribeInstancesInput{}
37 if args.off == "" {
38 filter := ec2types.Filter{
39 Name: aws.String("instance-state-name"),
40 Values: []string{"running"},
41 }
42 describeInstancesInput.Filters = []ec2types.Filter{filter}
43 }
44
45 var reMatch *regexp.Regexp
46 if args.match != "" {
47 var err error
48 reMatch, err = regexp.Compile(args.match)
49 if err != nil {
50 fatalIfErr(err)
51 }
52 }
53
54 insts := map[string]*ec2types.Instance{}
55 for _, region := range args.regions {
56 ec2conn := ec2.NewFromConfig(config, func(o *ec2.Options) {
57 o.Region = region
58 })
59 paginator := ec2.NewDescribeInstancesPaginator(ec2conn, &describeInstancesInput)
60 for paginator.HasMorePages() {
61 output, err := paginator.NextPage(ctx)
62 fatalIfErr(err)
63 for _, r := range output.Reservations {
64 for _, i := range r.Instances {
65 for _, tag := range i.Tags {
66 // limit to instances with a Name tag
67 if *tag.Key == "Name" {
68 if reMatch != nil && !reMatch.MatchString(*tag.Value) {
69 continue
70 }
71 instance := i
72 insts[*tag.Value] = &instance
73 continue
74 }
75 }
76 }
77 }
78 }
79 }
80
81 if len(insts) == 0 {
82 fmt.Println("No instances found")
83 }
84
85 var rtype string
86 if args.aRecord {
87 rtype = "A"
88 } else {
89 rtype = "CNAME"

Callers 1

MainFunction · 0.85

Calls 5

lookupZoneFunction · 0.85
batchChangesFunction · 0.85
waitForChangeFunction · 0.85
fatalIfErrFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected