Skip to content

Instantly share code, notes, and snippets.

@snandam
Last active August 4, 2025 22:55
Show Gist options
  • Save snandam/d5a3ec9c8d8daaf41e999d18a3df09d3 to your computer and use it in GitHub Desktop.
Save snandam/d5a3ec9c8d8daaf41e999d18a3df09d3 to your computer and use it in GitHub Desktop.
Create, manage ec2 instances created from an AMI into a VPC
#!/bin/bash
# EC2 Instance Creation Script
# This script creates multiple EC2 instances from an existing AMI
set -e # Exit on any error
# Configuration - UPDATE THESE VALUES
AMI_ID="" # Replace with your AMI ID
INSTANCE_TYPE="t2.micro" # Instance type
KEY_NAME="y" # Your EC2 key pair name
SECURITY_GROUP="" # Security group ID
SUBNET_ID="" # Subnet ID (optional)
INSTANCE_NAME_PREFIX="MyInstance" # Prefix for instance names
PROJECT_TAG="MyProject" # Tag value to group instances
ENVIRONMENT_TAG="dev" # Environment tag (dev/staging/prod)
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to check if AWS CLI is installed and configured
check_aws_cli() {
if ! command -v aws &> /dev/null; then
print_error "AWS CLI is not installed. Please install it first."
exit 1
fi
if ! aws sts get-caller-identity &> /dev/null; then
print_error "AWS CLI is not configured or credentials are invalid."
exit 1
fi
print_status "AWS CLI is properly configured"
}
# Function to validate AMI exists
validate_ami() {
print_status "Validating AMI: $AMI_ID"
if ! aws ec2 describe-images --image-ids "$AMI_ID" &> /dev/null; then
print_error "AMI $AMI_ID not found or not accessible"
exit 1
fi
print_status "AMI validation successful"
}
# Function to create instances
create_instances() {
local count=$1
local timestamp=$(date +"%Y%m%d-%H%M%S")
print_status "Creating $count EC2 instances with tags..."
# Build the tag specifications
local tag_spec="ResourceType=instance,Tags=["
tag_spec="${tag_spec}{Key=Project,Value=${PROJECT_TAG}},"
tag_spec="${tag_spec}{Key=Environment,Value=${ENVIRONMENT_TAG}},"
tag_spec="${tag_spec}{Key=CreatedBy,Value=ec2-creation-script},"
tag_spec="${tag_spec}{Key=CreatedAt,Value=${timestamp}},"
tag_spec="${tag_spec}{Key=ManagedBy,Value=automation}"
tag_spec="${tag_spec}]"
# Build the AWS CLI command
local cmd="aws ec2 run-instances"
cmd="$cmd --image-id $AMI_ID"
cmd="$cmd --count $count"
cmd="$cmd --instance-type $INSTANCE_TYPE"
cmd="$cmd --key-name $KEY_NAME"
cmd="$cmd --security-group-ids $SECURITY_GROUP"
cmd="$cmd --tag-specifications '$tag_spec'"
# Add subnet if specified
if [[ -n "$SUBNET_ID" && "$SUBNET_ID" != "subnet-xxxxxxxxx" ]]; then
cmd="$cmd --subnet-id $SUBNET_ID"
fi
# Execute the command and capture output
local result
if result=$(eval "$cmd" 2>&1); then
# Extract instance IDs from the result
local instance_ids
instance_ids=$(echo "$result" | jq -r '.Instances[].InstanceId' 2>/dev/null || echo "$result" | grep -o 'i-[a-zA-Z0-9]*')
if [[ -n "$instance_ids" ]]; then
print_status "Successfully created instances:"
local counter=1
echo "$instance_ids" | while read -r instance_id; do
echo " - $instance_id"
# Add individual Name tag for each instance
local instance_name="${INSTANCE_NAME_PREFIX}-${counter}"
aws ec2 create-tags --resources "$instance_id" --tags Key=Name,Value="$instance_name" 2>/dev/null || true
((counter++))
done
print_status "All instances tagged with:"
echo " - Project: $PROJECT_TAG"
echo " - Environment: $ENVIRONMENT_TAG"
echo " - CreatedBy: ec2-creation-script"
echo " - CreatedAt: $timestamp"
echo " - ManagedBy: automation"
else
print_error "Could not extract instance IDs from AWS response"
exit 1
fi
else
print_error "Failed to create instances: $result"
exit 1
fi
}
# Function to wait for instances to be running
wait_for_instances() {
print_status "Waiting for instances to reach 'running' state..."
# Get instance IDs using the project tag
local instance_ids
instance_ids=$(aws ec2 describe-instances \
--filters "Name=tag:Project,Values=$PROJECT_TAG" "Name=tag:ManagedBy,Values=automation" "Name=instance-state-name,Values=pending,running" \
--query 'Reservations[].Instances[].InstanceId' \
--output text)
if [[ -n "$instance_ids" ]]; then
aws ec2 wait instance-running --instance-ids $instance_ids
print_status "All instances are now running!"
# Display instance information
print_status "Instance details:"
aws ec2 describe-instances \
--filters "Name=tag:Project,Values=$PROJECT_TAG" "Name=tag:ManagedBy,Values=automation" \
--query 'Reservations[].Instances[].[InstanceId,State.Name,PublicIpAddress,PrivateIpAddress,Tags[?Key==`Name`].Value|[0]]' \
--output table
else
print_warning "No instances found with Project tag: $PROJECT_TAG"
fi
}
# Main script
main() {
echo "=================================================="
echo " EC2 Instance Creation Script"
echo "=================================================="
# Get number of instances to create
if [[ $# -eq 0 ]]; then
read -p "Enter number of instances to create: " NUM_INSTANCES
else
NUM_INSTANCES=$1
fi
# Validate input
if ! [[ "$NUM_INSTANCES" =~ ^[0-9]+$ ]] || [[ "$NUM_INSTANCES" -lt 1 ]] || [[ "$NUM_INSTANCES" -gt 100 ]]; then
print_error "Please enter a valid number between 1 and 100"
exit 1
fi
print_status "Configuration:"
echo " AMI ID: $AMI_ID"
echo " Instance Type: $INSTANCE_TYPE"
echo " Key Pair: $KEY_NAME"
echo " Security Group: $SECURITY_GROUP"
echo " Subnet ID: ${SUBNET_ID:-"Default"}"
echo " Project Tag: $PROJECT_TAG"
echo " Environment Tag: $ENVIRONMENT_TAG"
echo " Number of Instances: $NUM_INSTANCES"
echo
# Confirm before proceeding
read -p "Do you want to proceed? (y/N): " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
print_warning "Operation cancelled"
exit 0
fi
# Run the creation process
check_aws_cli
validate_ami
create_instances "$NUM_INSTANCES"
wait_for_instances
print_status "Instance creation completed successfully!"
}
# Run main function with all arguments
main "$@"
#!/bin/bash
# EC2 Instance Management Script
# This script manages (start/stop/status) EC2 instances
set -e # Exit on any error
# Configuration
DEFAULT_PROJECT_TAG="MyProject" # Default project tag to filter instances
DEFAULT_ENVIRONMENT_TAG="dev" # Default environment tag
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_header() {
echo -e "${BLUE}$1${NC}"
}
# Function to check if AWS CLI is installed and configured
check_aws_cli() {
if ! command -v aws &> /dev/null; then
print_error "AWS CLI is not installed. Please install it first."
exit 1
fi
if ! aws sts get-caller-identity &> /dev/null; then
print_error "AWS CLI is not configured or credentials are invalid."
exit 1
fi
}
# Function to get instance IDs
get_instance_ids() {
local source=$1
local instance_ids=""
case $source in
"project")
local project_tag="${2:-$DEFAULT_PROJECT_TAG}"
print_status "Finding instances with Project tag: $project_tag" >&2
# First, let's try with JSON output to avoid potential XML issues
local json_output
json_output=$(aws ec2 describe-instances \
--filters "Name=tag:Project,Values=$project_tag" "Name=instance-state-name,Values=running,stopped" \
--query 'Reservations[].Instances[].InstanceId' \
--output json 2>&1)
if [[ $? -ne 0 ]]; then
print_error "AWS describe-instances failed: $json_output" >&2
exit 1
fi
# Parse JSON to get instance IDs
instance_ids=$(echo "$json_output" | jq -r '.[]' 2>/dev/null | tr '\n' ' ')
# Fallback to text output if jq is not available
if [[ -z "$instance_ids" || "$instance_ids" == "null " ]]; then
instance_ids=$(aws ec2 describe-instances \
--filters "Name=tag:Project,Values=$project_tag" "Name=instance-state-name,Values=running,stopped" \
--query 'Reservations[].Instances[].InstanceId' \
--output text)
fi
;;
"environment")
local env_tag="${2:-$DEFAULT_ENVIRONMENT_TAG}"
print_status "Finding instances with Environment tag: $env_tag" >&2
instance_ids=$(aws ec2 describe-instances \
--filters "Name=tag:Environment,Values=$env_tag" "Name=instance-state-name,Values=running,stopped" \
--query 'Reservations[].Instances[].InstanceId' \
--output text)
;;
"both")
local project_tag="${2:-$DEFAULT_PROJECT_TAG}"
local env_tag="${3:-$DEFAULT_ENVIRONMENT_TAG}"
print_status "Finding instances with Project: $project_tag AND Environment: $env_tag" >&2
instance_ids=$(aws ec2 describe-instances \
--filters "Name=tag:Project,Values=$project_tag" "Name=tag:Environment,Values=$env_tag" "Name=instance-state-name,Values=running,stopped" \
--query 'Reservations[].Instances[].InstanceId' \
--output text)
;;
"managed")
print_status "Finding all managed instances (ManagedBy=automation)" >&2
instance_ids=$(aws ec2 describe-instances \
--filters "Name=tag:ManagedBy,Values=automation" "Name=instance-state-name,Values=running,stopped" \
--query 'Reservations[].Instances[].InstanceId' \
--output text)
;;
"manual")
read -p "Enter instance IDs (space-separated): " instance_ids
;;
"custom")
read -p "Enter tag name to filter instances by: " tag_name
read -p "Enter tag value: " tag_value
print_status "Finding instances with $tag_name: $tag_value" >&2
instance_ids=$(aws ec2 describe-instances \
--filters "Name=tag:$tag_name,Values=$tag_value" "Name=instance-state-name,Values=running,stopped" \
--query 'Reservations[].Instances[].InstanceId' \
--output text)
;;
esac
if [[ -z "$instance_ids" || "$instance_ids" == "None" ]]; then
print_error "No instance IDs found with the specified criteria!" >&2
exit 1
fi
# Clean up instance IDs - normalize whitespace
instance_ids=$(echo "$instance_ids" | sed 's/[[:space:]]\+/ /g' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
# Validate instance ID format (should be i-xxxxxxxxxxxxxxxxx)
for id in $instance_ids; do
if [[ ! "$id" =~ ^i-[0-9a-f]{8,17}$ ]]; then
print_error "Invalid instance ID format: '$id'" >&2
exit 1
fi
done
echo "$instance_ids"
}
# Function to display instance status
show_status() {
local instance_ids=$1
print_header "Current Instance Status:"
# Convert space-separated IDs to array for proper quoting
IFS=' ' read -ra ids_array <<< "$instance_ids"
if [ ${#ids_array[@]} -eq 0 ]; then
print_error "No instance IDs provided"
return 1
fi
print_status "Querying status for ${#ids_array[@]} instance(s)..."
# Try with JSON output first, then parse manually to avoid XML issues
local json_result
json_result=$(aws ec2 describe-instances --instance-ids "${ids_array[@]}" --output json 2>&1)
if [[ $? -ne 0 ]]; then
print_error "Failed to get instance status: $json_result"
return 1
fi
# Parse and display results
echo "$json_result" | jq -r '.Reservations[].Instances[] | [.InstanceId, .State.Name, .InstanceType, .PublicIpAddress // "N/A", .PrivateIpAddress // "N/A", (.Tags[] | select(.Key=="Name") | .Value) // "N/A"] | @tsv' 2>/dev/null | \
{
printf "%-19s %-10s %-12s %-15s %-15s %s\n" "Instance ID" "State" "Type" "Public IP" "Private IP" "Name"
printf "%-19s %-10s %-12s %-15s %-15s %s\n" "-------------------" "----------" "------------" "---------------" "---------------" "----"
while IFS=$'\t' read -r id state type pub_ip priv_ip name; do
printf "%-19s %-10s %-12s %-15s %-15s %s\n" "$id" "$state" "$type" "$pub_ip" "$priv_ip" "$name"
done
}
# Fallback to table format if jq fails
if [[ $? -ne 0 ]]; then
print_warning "jq not available, using basic table format"
aws ec2 describe-instances --instance-ids "${ids_array[@]}" \
--query 'Reservations[].Instances[].[InstanceId,State.Name,InstanceType,PublicIpAddress,PrivateIpAddress,Tags[?Key==`Name`].Value|[0]]' \
--output table
fi
}
# Function to start instances
start_instances() {
local instance_ids=$1
print_status "Starting instances: $instance_ids"
IFS=' ' read -ra ids_array <<< "$instance_ids"
local stopped_instances
stopped_instances=$(aws ec2 describe-instances --instance-ids "${ids_array[@]}" \
--filters "Name=instance-state-name,Values=stopped" \
--query 'Reservations[].Instances[].InstanceId' \
--output text)
if [[ -n "$stopped_instances" ]]; then
aws ec2 start-instances --instance-ids $stopped_instances
print_status "Start command sent. Waiting for instances to reach 'running' state..."
aws ec2 wait instance-running --instance-ids $stopped_instances
print_status "All instances are now running!"
show_status "$instance_ids"
else
print_warning "No stopped instances found to start"
fi
}
# Function to stop instances
stop_instances() {
local instance_ids=$1
print_status "Stopping instances: $instance_ids"
IFS=' ' read -ra ids_array <<< "$instance_ids"
local running_instances
running_instances=$(aws ec2 describe-instances --instance-ids "${ids_array[@]}" \
--filters "Name=instance-state-name,Values=running" \
--query 'Reservations[].Instances[].InstanceId' \
--output text)
if [[ -n "$running_instances" ]]; then
aws ec2 stop-instances --instance-ids $running_instances
print_status "Stop command sent. Waiting for instances to reach 'stopped' state..."
aws ec2 wait instance-stopped --instance-ids $running_instances
print_status "All instances are now stopped!"
show_status "$instance_ids"
else
print_warning "No running instances found to stop"
fi
}
# Function to terminate instances
terminate_instances() {
local instance_ids=$1
print_warning "WARNING: This will permanently delete the instances!"
IFS=' ' read -ra ids_array <<< "$instance_ids"
# Show what will be terminated
print_status "Instances to be terminated:"
aws ec2 describe-instances --instance-ids "${ids_array[@]}" \
--query 'Reservations[].Instances[].[InstanceId,Tags[?Key==`Name`].Value|[0],Tags[?Key==`Project`].Value|[0],Tags[?Key==`Environment`].Value|[0]]' \
--output table
read -p "Are you sure you want to terminate these instances? (type 'yes' to confirm): " confirm
if [[ "$confirm" == "yes" ]]; then
print_status "Terminating instances: $instance_ids"
local result
result=$(aws ec2 terminate-instances --instance-ids "${ids_array[@]}" --output json 2>&1)
if [[ $? -eq 0 ]]; then
print_status "Termination command sent. Waiting for instances to be fully terminated..."
aws ec2 wait instance-terminated --instance-ids "${ids_array[@]}"
print_status "✓ All ${#ids_array[@]} instances have been terminated successfully"
else
print_error "Failed to terminate instances: $result"
fi
else
print_warning "Termination cancelled"
fi
}
# Function to reboot instances
reboot_instances() {
local instance_ids=$1
print_status "Rebooting instances: $instance_ids"
IFS=' ' read -ra ids_array <<< "$instance_ids"
local running_instances
running_instances=$(aws ec2 describe-instances --instance-ids "${ids_array[@]}" \
--filters "Name=instance-state-name,Values=running" \
--query 'Reservations[].Instances[].InstanceId' \
--output text)
if [[ -n "$running_instances" ]]; then
aws ec2 reboot-instances --instance-ids $running_instances
print_status "Reboot command sent to running instances!"
else
print_warning "No running instances found to reboot"
fi
}
# Function to show help
show_help() {
echo "Usage: $0 [COMMAND] [OPTIONS]"
echo
echo "Commands:"
echo " start Start stopped instances"
echo " stop Stop running instances"
echo " status Show current status of instances"
echo " reboot Reboot running instances"
echo " terminate Terminate instances (permanent deletion)"
echo " help Show this help message"
echo
echo "Instance Selection Options:"
echo " -p, --project [TAG] Select by project tag (default: $DEFAULT_PROJECT_TAG)"
echo " -e, --environment [TAG] Select by environment tag (default: $DEFAULT_ENVIRONMENT_TAG)"
echo " -b, --both [PROJECT] [ENV] Select by both project and environment tags"
echo " -a, --managed Select all managed instances (ManagedBy=automation)"
echo " -m, --manual Manually enter instance IDs"
echo " -c, --custom Select by custom tag name/value"
echo
echo "Examples:"
echo " $0 start # Start instances with default project tag"
echo " $0 stop --project MyWebApp # Stop instances tagged with Project=MyWebApp"
echo " $0 status --environment prod # Show status of production instances"
echo " $0 terminate --both MyApp staging # Terminate instances with Project=MyApp AND Environment=staging"
echo " $0 start --managed # Start all automation-managed instances"
echo " $0 reboot --custom # Reboot instances selected by custom tag"
}
# Main function
main() {
echo "=================================================="
echo " EC2 Instance Management Script"
echo "=================================================="
check_aws_cli
# Parse command line arguments
local command=""
local source="project" # Default to project tag
local tag_value=""
local env_value=""
while [[ $# -gt 0 ]]; do
case $1 in
start|stop|status|reboot|terminate)
command=$1
shift
;;
-p|--project)
source="project"
if [[ -n "$2" && "$2" != -* ]]; then
tag_value=$2
shift
fi
shift
;;
-e|--environment)
source="environment"
if [[ -n "$2" && "$2" != -* ]]; then
tag_value=$2
shift
fi
shift
;;
-b|--both)
source="both"
if [[ -n "$2" && "$2" != -* ]]; then
tag_value=$2
shift
fi
if [[ -n "$2" && "$2" != -* ]]; then
env_value=$2
shift
fi
shift
;;
-a|--managed)
source="managed"
shift
;;
-m|--manual)
source="manual"
shift
;;
-c|--custom)
source="custom"
shift
;;
help|--help|-h)
show_help
exit 0
;;
*)
print_error "Unknown option: $1"
show_help
exit 1
;;
esac
done
# If no command provided, show interactive menu
if [[ -z "$command" ]]; then
echo "Select an action:"
echo "1) Start instances"
echo "2) Stop instances"
echo "3) Show status"
echo "4) Reboot instances"
echo "5) Terminate instances"
echo "6) Exit"
read -p "Enter choice (1-6): " choice
case $choice in
1) command="start" ;;
2) command="stop" ;;
3) command="status" ;;
4) command="reboot" ;;
5) command="terminate" ;;
6) exit 0 ;;
*) print_error "Invalid choice"; exit 1 ;;
esac
# Ask for instance selection method
echo
echo "How do you want to select instances?"
echo "1) By project tag (default: $DEFAULT_PROJECT_TAG)"
echo "2) By environment tag (default: $DEFAULT_ENVIRONMENT_TAG)"
echo "3) By both project and environment tags"
echo "4) All managed instances (automation created)"
echo "5) Enter manually"
echo "6) By custom tag"
read -p "Enter choice (1-6): " source_choice
case $source_choice in
1)
source="project"
read -p "Enter project tag value (default: $DEFAULT_PROJECT_TAG): " tag_value
;;
2)
source="environment"
read -p "Enter environment tag value (default: $DEFAULT_ENVIRONMENT_TAG): " tag_value
;;
3)
source="both"
read -p "Enter project tag value (default: $DEFAULT_PROJECT_TAG): " tag_value
read -p "Enter environment tag value (default: $DEFAULT_ENVIRONMENT_TAG): " env_value
;;
4) source="managed" ;;
5) source="manual" ;;
6) source="custom" ;;
*) print_error "Invalid choice"; exit 1 ;;
esac
fi
# Get instance IDs based on selection method
local instance_ids
if [[ "$source" == "both" ]]; then
instance_ids=$(get_instance_ids "$source" "${tag_value:-$DEFAULT_PROJECT_TAG}" "${env_value:-$DEFAULT_ENVIRONMENT_TAG}")
else
instance_ids=$(get_instance_ids "$source" "${tag_value}")
fi
print_status "Selected instances: $instance_ids"
# Clean word count by using array - properly handle the string
IFS=' ' read -ra clean_array <<< "$instance_ids"
print_status "Number of instances: ${#clean_array[@]}"
echo
# Execute command
case $command in
"start")
start_instances "$instance_ids"
;;
"stop")
stop_instances "$instance_ids"
;;
"status")
show_status "$instance_ids"
;;
"reboot")
reboot_instances "$instance_ids"
;;
"terminate")
terminate_instances "$instance_ids"
;;
esac
}
# Run main function with all arguments
main "$@"

EC2 Management Scripts

Two bash scripts for creating and managing AWS EC2 instances with automatic tagging and lifecycle management.

Scripts Overview

create_ec2_instances.sh

Creates multiple EC2 instances from a specified AMI with automatic tagging for project organization. Features:

  • Validates AWS configuration and AMI availability
  • Creates instances with consistent tagging (Project, Environment, CreatedBy, etc.)
  • Waits for instances to reach running state
  • Displays instance details upon completion

manage_ec2_instances.sh

Manages existing EC2 instances by tag-based filtering. Features:

  • Filter instances by Project, Environment, or custom tags
  • Start, stop, reboot, terminate, and check status of instances
  • Batch operations on multiple instances
  • Clean output with confirmation prompts for destructive actions

Prerequisites

Before using the creation script, ensure these AWS resources exist:

  • VPC: Virtual Private Cloud must be created
  • Subnet: Subnet within the VPC (specify subnet ID in script)
  • Security Group: Security group with appropriate inbound/outbound rules
  • Key Pair: EC2 key pair for SSH access to instances
  • AMI: Amazon Machine Image ID that you want to launch
  • IAM Permissions: AWS credentials with EC2 create/describe/terminate permissions

Usage Examples

Create Instances

 ./create_ec2_instances.sh 3                                   
==================================================
           EC2 Instance Creation Script
==================================================
[INFO] Configuration:
  AMI ID: ami-0d5d5d01d9b1138ef
  Instance Type: t2.micro
  Key Pair: aivibe-vss-key
  Security Group: sg-050e3dd08db2c65b0
  Subnet ID: subnet-03e9112730837bc3e
  Project Tag: MyProject
  Environment Tag: dev
  Number of Instances: 3

Do you want to proceed? (y/N): y
[INFO] AWS CLI is properly configured
[INFO] Validating AMI: ami-0d5d5d01d9b1138ef
[INFO] AMI validation successful
[INFO] Creating 3 EC2 instances with tags...
[INFO] Successfully created instances:
  - i-0e222a380771946bc
  - i-0504c1821c4501ab6
  - i-0f7b1a3742e26b67b
[INFO] All instances tagged with:
  - Project: MyProject
  - Environment: dev
  - CreatedBy: ec2-creation-script
  - CreatedAt: 20250804-154130
  - ManagedBy: automation
[INFO] Waiting for instances to reach 'running' state...
[INFO] All instances are now running!
[INFO] Instance details:
-----------------------------------------------------------------------------
|                             DescribeInstances                             |
+----------------------+-------------+-------+-------------+----------------+
|  i-0f7b1a3742e26b67b |  running    |  None |  190.0.2.24 |  MyInstance-3  |
|  i-0e222a380771946bc |  running    |  None |  190.0.2.29 |  MyInstance-1  |
|  i-0504c1821c4501ab6 |  running    |  None |  190.0.2.25 |  MyInstance-2  |
+----------------------+-------------+-------+-------------+----------------+
[INFO] Instance creation completed successfully!

Manage Instances

 ./manage_ec2_instances.sh status --project MyProject
==================================================
           EC2 Instance Management Script
==================================================
[INFO] Finding instances with Project tag: MyProject
[INFO] Selected instances: i-027eea3b5fcda5e1d
[INFO] Number of instances: 1

Current Instance Status:
[INFO] Querying status for 1 instance(s)...
Instance ID         State      Type         Public IP       Private IP      Name
------------------- ---------- ------------ --------------- --------------- ----
i-027eea3b5fcda5e1d running    t2.micro     N/A             190.0.2.56      MyInstance-1



 ./manage_ec2_instances.sh status terminate --project MyProject
==================================================
           EC2 Instance Management Script
==================================================
[INFO] Finding instances with Project tag: MyProject
[INFO] Selected instances: i-0f7b1a3742e26b67b i-0e222a380771946bc i-0504c1821c4501ab6
[INFO] Number of instances: 3

[WARNING] WARNING: This will permanently delete the instances!
[INFO] Instances to be terminated:
-------------------------------------------------------------
|                     DescribeInstances                     |
+----------------------+----------------+------------+------+
|  i-0f7b1a3742e26b67b |  MyInstance-3  |  MyProject |  dev |
|  i-0e222a380771946bc |  MyInstance-1  |  MyProject |  dev |
|  i-0504c1821c4501ab6 |  MyInstance-2  |  MyProject |  dev |
+----------------------+----------------+------------+------+
Are you sure you want to terminate these instances? (type 'yes' to confirm): yes
[INFO] Terminating instances: i-0f7b1a3742e26b67b i-0e222a380771946bc i-0504c1821c4501ab6
[INFO] Termination command sent. Waiting for instances to be fully terminated...
[INFO] ✓ All 3 instances have been terminated successfully
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment