Good day time, profs. I am a bit new to aws cli framework. What i need to get via console is a list of available instances in a specified region with a limit number of that type.
For example, command should look like:
aws ec2 describe-available-instances --region us-west-1 --type [t1.micro, c3.4xlarge, etc. If not set - list all types]
and the output will look like:
t1.micro 5
c3.4xlarge 10
m4.4x 20
Go to VPC dashboard https://console.aws.amazon.com/vpc/home and click on Running instances -> See all regions . Example output: $ aws. print-all-instances Listing Instances in region: 'eu-north-1'.. "EC2: i-0548d1de00c39f923: terminated" "EC2: i-0fadd093234a1c21d: running" Listing Instances in region: 'ap-south-1'..
Open the Amazon Elastic Cloud Compute (Amazon EC2) console. From the navigation bar, view the options in the Region selector. On the navigation pane, choose EC2 Dashboard. In the Service Health section, view the list of Availability Zones under Availability Zone Status.
You can achieve this output as JSON with AWS CLI and JQ.
1) Call the describe-instances command. This retrieves all sorts of metadata about an EC2 Instance, including the Instance Type. We will eventually filter our output down to Instance Type alone.
aws ec2 describe-instances
2) Specify an instance-type filter via the --filter
param. If this is not specified, this query will display all instance types where count > 0. This will not include 0-count types because the output is derived from your collection of EC2 instances.
--filters "Name=instance-type,Values=t2.micro,t2.small"
3) Specify a region via the --region
param. If this is not specified, AWS CLI will attempt to use your default region.
--region us-east-1
4) Specify your query. Output an array of key/value pairs where Key = "InstanceType", Value = InstanceType.
--query "Reservations[].Instances[].{InstanceType:InstanceType}"
5) Use jq to group by Instance Type, so that like-InstanceTypes will be aggregated.
| jq "group_by(.InstanceType)
6) Map a final array of key/value pairs, where key = InstanceType and value = jq length
, or in other words the sum of each group of instance types.
| map({(.[0].InstanceType):length})
aws ec2 describe-instances --region us-east-1 --filters "Name=instance-type,Values=t2.micro,t2.small" --query "Reservations[].Instances[].{InstanceType:InstanceType}" | jq "group_by(.InstanceType) | map({(.[0].InstanceType):length})"
[
{
"t2.micro": 12
},
{
"t2.small": 2
}
]
If you're trying to retrieve the Amazon GameLift per-instance-type limits, use describe-ec2-instance-limits:
aws gamelift describe-ec2-instance-limits --query 'EC2InstanceLimits[].{EC2InstanceType:EC2InstanceType,InstanceLimit:InstanceLimit}' --region us-east-1 --output text
With purpose see all instances without filters - use this:
aws ec2 describe-instances --output text \
--query 'Reservations[*].Instances[*].[InstanceType]' | sort | uniq -c
Output will look like this:
1 m3.medium
1 m4.10xlarge
9 m4.xlarge
6 t2.large
5 t2.medium
4 t2.micro
2 t2.xlarge
And with purpose to filter by specific type - just add filter, like this: --filters "Name=instance-type,Values=t2.micro,t2.small"
, your comand will look like this:
aws ec2 describe-instances --output text \
--filters "Name=instance-type,Values=t2.micro,t2.small" \
--query 'Reservations[*].Instances[*].[InstanceType]' | sort | uniq -c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With