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

Turn on JavaScript to leave a comment.

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

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers
Exit mobile version
%%footer%%