AWS Classroom notes 23/Nov/2023

AWS CLI

  • Script to terminate all ec2 instances with some tag and value
#!/bin/bash

# This script will terminate all the ec2 instances with a particular tag
# in all regions
# todo: replace this with keyword arguments --tagName --tagValue 
# todo: try to terminate ec2 when --action terminate
# action [start|stop|terminate]
tagkey=$1
tagValue=$2

# iterate over all regions
for region in $(aws ec2 describe-regions --query "Regions[].RegionName" --output text)
do
    echo "finding ec2 instances with tag $tagkey = $tagValue in $region "
    # findout all ec2 instances with some label
    instanceIds=$(aws ec2 describe-instances --region "us-west-2" --query "Reservations[].Instances[].InstanceId" --output text --filters "Name=tag:$tagkey,Values=$tagValue" --region $region)
    if [[ -n "$instanceIds" ]]; then
        echo "instance ids found in region $region with matching labels are $instanceIds"
        aws ec2 terminate-instances --region $region --instance-ids $instanceIds
    else
        echo "found nothing"
    fi
done
  • Sample execution manageec2.sh Env Dev

Horizontally scaled web application with zero down time deployments

  • Overview
    Preview
  • First step:

    • How to create AMI
    • How to automate AMI creation

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

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

Please turn AdBlock off
Social Network Integration by Acurax Social Media Branding Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube