AWS Classroomnotes 24/Sep/2023


  • Commands to get
    • instance ids aws ec2 describe-instances --query "Reservations[].Instances[].InstanceId"
    • tags: aws ec2 describe-instances --query "Reservations[].Instances[].Tags"
    • private ip addresses: aws ec2 describe-instances --query "Reservations[].Instances[].PrivateIpAddress"
  • Apply a tag env=dev to some ec2 instances

  • Sample script written

function apply_tags_to_all() {
    # Get all my ec2 instances optional
    instances=$(aws ec2 describe-instances --query "Reservations[].Instances[].InstanceId" --output text)
    echo "found instaces are $instances"
    aws ec2 create-tags --resources $instances --tags Key=env,Value=dev

# right now this works only for tag env and value dev
function get_instances_by_tag() {
    instances=$(aws ec2 describe-instances --filters "Name=tag:env,Values=dev" --query "Reservations[].Instances[].InstanceId" --output text)
    echo $instances

# get all ec2 instance ids based on tag value

echo "found instances $instances"
aws ec2 stop-instances --instance-ids $instances

#aws ec2 start-instances --instance-ids $(instances)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner