@@ -133,6 +133,7 @@ Cloud Resource Counter (v0.7.0) running with:
133
133
Activity
134
134
* Retrieving Account ID...OK (240520192079)
135
135
* Retrieving EC2 counts...................OK (5)
136
+ * Retrieving EC2 K8 related VMs Sub-instance counts...................OK (1)
136
137
* Retrieving Spot instance counts...................OK (4)
137
138
* Retrieving EBS volume counts...................OK (9)
138
139
* Retrieving Unique container counts...................OK (3)
@@ -151,7 +152,7 @@ As you can see above, no command line arguments were necessary: it used my defau
151
152
Here is what the CSV file looks like. It is important to mention that this tool was run TWICE to collect the results of two different accounts/profiles.
152
153
153
154
``` csv
154
- Account ID,Timestamp,Region,# of EC2 Instances,# of Spot Instances,# of EBS Volumes,# of Unique Containers,# of Lambda Functions,# of RDS Instances,# of Lightsail Instances,# of S3 Buckets,# of EKS Nodes
155
+ Account ID,Timestamp,Region,# of EC2 Instances,# of EC2 K8 related VMs Sub-instances,# of Spot Instances,# of EBS Volumes,# of Unique Containers,# of Lambda Functions,# of RDS Instances,# of Lightsail Instances,# of S3 Buckets,# of EKS Nodes
155
156
896149672290,2020-10-20T16:29:39-04:00,ALL_REGIONS,2,3,7,3,2,3,2,2,2
156
157
240520192079,2020-10-21T16:24:06-04:00,ALL_REGIONS,5,4,9,3,12,7,0,13,0
157
158
```
@@ -267,9 +268,10 @@ The `aws-resource-counter` examines the following resources:
267
268
1. ** EC2** . We count the number of EC2 ** running** instances (both " normal" and Spot instances) across all regions.
268
269
269
270
* For EC2 instances, we only count those _without_ an Instance Lifecycle tag (which is either ` spot` or ` scheduled` ).
271
+ * For EC2 K8 related VMs sub-instances, we only count those with a tag of ` aws:eks:cluster-name` .
270
272
* For Spot instance, we only count those with an Instance Lifecycle tag of ` spot` .
271
273
272
- * This is stored in the generated CSV file under the " # of EC2 Instances" and " # of Spot Instances" columns.
274
+ * This is stored in the generated CSV file under the " # of EC2 Instances" , " # of EC2 K8 related VMs Sub-instances " , and " # of Spot Instances" columns.
273
275
274
276
1. ** EBS Volumes.** We count the number of " attached" EBS volumes across all regions.
275
277
@@ -348,7 +350,7 @@ To collect the total number of EC2 instances across all regions, we will need to
348
350
```bash
349
351
$ aws ec2 describe-regions $aws_p \
350
352
--filters Name=opt-in-status,Values=opt-in-not-required,opted-in \
351
- --region us-east-1 --output text --query Regions[].RegionName
353
+ --region us-east-1 --output text --query ' Regions[].RegionName'
352
354
eu-north-1 ap-south-1 eu-west-3 ...
353
355
```
354
356
@@ -364,7 +366,7 @@ We will be using the results of this command to "iterate" over all regions. To m
364
366
```bash
365
367
$ ec2_r=$(aws ec2 describe-regions $aws_p \
366
368
--filters Name=opt-in-status,Values=opt-in-not-required,opted-in \
367
- --region us-east-1 --output text --query Regions[].RegionName )
369
+ --region us-east-1 --output text --query ' Regions[].RegionName' )
368
370
```
369
371
370
372
You can show the list of regions for your account by using the `echo` command:
@@ -417,6 +419,32 @@ The second and third lines are our call to `describe-instances` (as shown above)
417
419
418
420
In the fourth line, we paste all of the values into a long addition and use `bc` to sum the values.
419
421
422
+ #### EC2 K8 Related VMs Subcount Instances
423
+
424
+ Here is the command to count the number of _EC K8 related VMs subcount_ instances for a given region:
425
+
426
+ ```bash
427
+ $ aws ec2 describe-instances $aws_p --no-paginate --region us-east-1 \
428
+ --filters Name=instance-state-name,Values=running \
429
+ --filters Name=tag-key,Values=' aws:eks:cluster-name' \
430
+ --query ' length(Reservations[].Instances[? ! not_null(InstanceLifecycle)].InstanceId[])'
431
+ 1
432
+ ```
433
+
434
+ This command is similar to the normal EC2 query, but now explicitly checks for EC2 instances whose `Tags` have that key `aws:eks:cluster-name`.
435
+
436
+ We will need to run this command over all regions. Here is what it looks like:
437
+
438
+ ```bash
439
+ $ for reg in $ec2_r; do \
440
+ aws ec2 describe-instances $aws_p --no-paginate --region $reg \
441
+ --filters Name=instance-state-name,Values=running \
442
+ --filters Name=tag-key,Values=' aws:eks:cluster-name' \
443
+ --query ' length(Reservations[].Instances[? ! not_null(InstanceLifecycle)].InstanceId[])' ; \
444
+ done | paste -s -d+ - | bc
445
+ 5
446
+ ```
447
+
420
448
#### Spot Instances
421
449
422
450
Here is the command to count the number of _Spot_ instances for a given region:
0 commit comments