Difference between revisions of "Aws ec2 describe-instances"
Jump to navigation
Jump to search
↑ https://www.bluematador.com/learn/aws-cli-cheatsheet
(24 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{lowercase}} | {{lowercase}} | ||
https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html | https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html | ||
− | |||
− | |||
== Examples == | == Examples == | ||
− | * <code>[[aws ec2 | + | * <code>[[Example output: aws ec2 describe-instances]]</code> |
* <code>[[aws ec2]] describe-instances [[--instance-ids]] </code> | * <code>[[aws ec2]] describe-instances [[--instance-ids]] </code> | ||
* <code>aws ec2 describe-instances | grep [[InstanceType]]</code> | * <code>aws ec2 describe-instances | grep [[InstanceType]]</code> | ||
* <code>aws ec2 describe-instances | grep [[AvailabilityZone]]</code> | * <code>aws ec2 describe-instances | grep [[AvailabilityZone]]</code> | ||
− | * <code>aws ec2 describe-instances | egrep "[[InstanceId]]|InstanceType|running"</code> | + | * <code>aws ec2 describe-instances | egrep "[[InstanceId]]|[[InstanceType]]|[[running]]"</code> |
* <code>aws ec2 describe-instances | egrep "InstanceId|YOUR_INSTANCE_NAME"</code> | * <code>aws ec2 describe-instances | egrep "InstanceId|YOUR_INSTANCE_NAME"</code> | ||
* <code>aws ec2 describe-instances | [[grep -A1]] '"Key": "Name"'</code> | * <code>aws ec2 describe-instances | [[grep -A1]] '"Key": "Name"'</code> | ||
Line 17: | Line 15: | ||
* <code>aws ec2 describe-instances | grep "[[GroupName]]|[[GroupId]]"</code> | * <code>aws ec2 describe-instances | grep "[[GroupName]]|[[GroupId]]"</code> | ||
− | State: | + | === List [[Instance ID]], [[Type]], status and [[Name]] === |
− | aws ec2 describe-instances | grep -iA2 -w state | grep Name | + | aws ec2 describe-instances | [[jq -r]] '.Reservations[].Instances[]|.InstanceId+" "+.InstanceType+" "+.State.Name+" "+(.Tags[] | select(.Key == "Name").Value)' |
+ | |||
+ | i-001d6ef48fd7da240 [[t3.xlarge]] [[stopped]] YourExample-[[workers]]-Node | ||
+ | i-00b1cf99a8fd118aa [[t2.large]] [[running]] your-machine-name | ||
+ | i-0a81356d71229695f t3.xlarge [[terminated]] YourExample-[[workers]]-Node | ||
+ | <ref>https://www.bluematador.com/learn/aws-cli-cheatsheet</ref> | ||
+ | |||
+ | === List Instances with [[public IP]] address and [[Name]] === | ||
+ | [[aws ec2]] describe-instances --query 'Reservations[*].Instances[?not_null([[PublicIpAddress]])]' | jq -r '.[][]|.PublicIpAddress+" "+(.Tags[]|select(.Key=="Name").Value)' | ||
+ | 3.125.113.44 your-instance-name1 | ||
+ | 18.197.142.11 your-instance-name2 | ||
+ | 3.67.83.67 your-instance-name3 | ||
+ | jq: error (at <stdin>:1904): [[Cannot iterate over null]] (null) | ||
+ | |||
+ | Remove Tags filter to avoid list of IPs to be truncated and get full list: | ||
+ | [[aws ec2]] describe-instances --query 'Reservations[*].Instances[?not_null(PublicIpAddress)]' | jq -r '.[][].PublicIpAddress' | ||
+ | |||
+ | === [[State]] === | ||
+ | [[aws ec2 describe-instances]] | grep -iA2 -w state | grep Name | ||
− | export INSTANCE_ID=$(aws ec2 run-instances .../... | [[jq -r]] '.Instances[].InstanceId') | + | export INSTANCE_ID=$(aws ec2 run-instances .../... | [[jq -r]] '.Instances[].InstanceId') |
=== Basic commands === | === Basic commands === | ||
Line 40: | Line 56: | ||
* <code>[[aws ssm start-session]]</code> | * <code>[[aws ssm start-session]]</code> | ||
* <code>[[aws ssm get-inventory]]</code> | * <code>[[aws ssm get-inventory]]</code> | ||
+ | * <code>[[aws ec2 get-console-output]]</code> | ||
+ | * [[GCP]]: <code>[[gcloud compute instances list]]</code> | ||
+ | * <code>[[aws ec2 describe-instance-status]]</code> | ||
== See also == | == See also == |
Latest revision as of 11:00, 26 February 2024
https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html
Contents
Examples[edit]
Example output: aws ec2 describe-instances
aws ec2 describe-instances --instance-ids
aws ec2 describe-instances | grep InstanceType
aws ec2 describe-instances | grep AvailabilityZone
aws ec2 describe-instances | egrep "InstanceId|InstanceType|running"
aws ec2 describe-instances | egrep "InstanceId|YOUR_INSTANCE_NAME"
aws ec2 describe-instances | grep -A1 '"Key": "Name"'
aws ec2 describe-instances --output text | egrep -w "Name|PLACEMENT"
aws ec2 describe-instances --region us-west-1
aws ec2 describe-instance --filter "Name=tag:Name,Values=YOUR-TAG-NAME" --query "Reservations[].Instances[?State.Name == 'running'].InstanceId[]" --output text)
List Instance ID, Type, status and Name[edit]
aws ec2 describe-instances | jq -r '.Reservations[].Instances[]|.InstanceId+" "+.InstanceType+" "+.State.Name+" "+(.Tags[] | select(.Key == "Name").Value)' i-001d6ef48fd7da240 t3.xlarge stopped YourExample-workers-Node i-00b1cf99a8fd118aa t2.large running your-machine-name i-0a81356d71229695f t3.xlarge terminated YourExample-workers-Node
List Instances with public IP address and Name[edit]
aws ec2 describe-instances --query 'Reservations[*].Instances[?not_null(PublicIpAddress)]' | jq -r '.[][]|.PublicIpAddress+" "+(.Tags[]|select(.Key=="Name").Value)' 3.125.113.44 your-instance-name1 18.197.142.11 your-instance-name2 3.67.83.67 your-instance-name3 jq: error (at <stdin>:1904): Cannot iterate over null (null)
Remove Tags filter to avoid list of IPs to be truncated and get full list: aws ec2 describe-instances --query 'Reservations[*].Instances[?not_null(PublicIpAddress)]' | jq -r '.[][].PublicIpAddress'
State[edit]
aws ec2 describe-instances | grep -iA2 -w state | grep Name
export INSTANCE_ID=$(aws ec2 run-instances .../... | jq -r '.Instances[].InstanceId')
Basic commands[edit]
aws ec2 describe-instances
An error occurred (AuthFailure) when calling the DescribeInstances operation: AWS was not able to validate the provided access credential
Solution: Review configuration with aws configure list
aws ec2 describe-instances --profile YOUR_PROFILE
Related commands[edit]
aws ec2 run-instances
aws ec2 describe-addresses
aws ec2 describe-instance-types
aws ec2 describe-network-interfaces
tags
aws list all
--region
aws-ec2-describe-instances-all-regions
aws ssm start-session
aws ssm get-inventory
aws ec2 get-console-output
- GCP:
gcloud compute instances list
aws ec2 describe-instance-status
See also[edit]
- AWS EC2, AWS::EC2,
aws ec2
[describe-instances | describe-instance-status
|run-instances | terminate-instances | stop-instances
|tags
|describe-vpcs
|describe-addresses
|describe-availability-zones
|describe-subnets
|import-key-pair
|create-key-pair
|create-vpc
|create-internet-gateway
|modify-instance-attribute | ec2-instance-connect | get-console-output
] - AWS EC2, Amazon EC2 API,
aws ec2, AWS::EC2
, Amazon EC2 Spot Instances, CPU credits, Instance type, EC2 limitations, 169.254.169.254, Instance metadata and user data (IMDS),InstanceType, InstanceId
, Amazon EC2 Auto Scaling, AWS EC2 Instance Connect, launch template, lifecycle, AWS Security group (SG), Amazon EC2 Recycle Bin, Amazon EC2 Mac Instances, Global View
Advertising: