Awscli snippets


Published:   November 26, 2021

Tags:

Fetch running instance with their private IP

1
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[NetworkInterfaces[0].PrivateIpAddresses[0].PrivateIpAddress,Tags[?Key==`Name`].Value| [0]]' --filters "Name=instance-state-name,Values=running" "Name=tag:environment,Values=production" --output text

Fetch running instance for given tag

1
2
3
4
# simple text output
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value|[0]]' --output text
# for table output
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value|[0]]' --output table

fetch just filtered instances using --filters option

1
aws ec2 describe-instances --output table   --query 'Reservations[].Instances[].[Tags[?Key==`Name`] | [0].Value, State.Name]' --filters Name=instance-state-name,Values=running Name=tag:billing,Values=devops

Fetch AMI-ID and Name start with given Name

1
aws ec2 describe-images --query 'Images[].[Tags[?Key==`Name`] | [0].Value,ImageId]' --filters 'Name=tag:Name,Values=funky-name-*' --output text

Linked post:

Reference:



Let me know if you have any questions or comments.
It will help me to improve/learn.


< Older   Further Reading   Newer >