Difference between revisions of "Aws ec2 describe-instances"

From wikieduonline
Jump to navigation Jump to search
Line 31: Line 31:
  
 
  Remove Tags filter to avoid list of IPs to be truncated and get full list:
 
  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'
+
  [[aws ec2]] describe-instances --query 'Reservations[*].Instances[?not_null(PublicIpAddress)]' | jq -r '.[][].PublicIpAddress'
  
 
=== State ===
 
=== State ===

Revision as of 09:35, 23 June 2022

https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html

Examples

  • 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)

Security Group

List Instance ID, Type and Name

aws ec2 describe-instances | jq -r '.Reservations[].Instances[]|.InstanceId+" "+.InstanceType+" "+(.Tags[] | select(.Key == "Name").Value)'

i-001d6ef48fd7da240 t3.xlarge YourExample-workers-Node
i-00b1cf99a8fd118aa t2.large your-machine-name
i-0a81356d71229695f t3.xlarge YourExample-workers-Node

[1]

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')

Basic commands

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

See also

  • https://www.bluematador.com/learn/aws-cli-cheatsheet
  • Advertising: