AWS EC2 Instance Yöneticisi

AWS EC2 instance'larını listeleyen, başlatan, durduran ve yöneten script.

Yayınlanma: 11.05.2024

Detaylı Bilgi

Bu script, AWS EC2 instance'larını yönetir. Instance'ları listeleyebilir, başlatabilir, durdurabilir ve yeniden başlatabilirsiniz.

Script Ne İşe Yarar?

Bu script, EC2 instance yönetimini sağlar:

  • EC2 instance'larını listeler
  • Instance'ı başlatır
  • Instance'ı durdurur
  • Instance'ı yeniden başlatır
  • Instance durumunu gösterir

Neden Kullanmalısınız?

EC2 instance yönetimi, cloud altyapı yönetimi için kritiktir:

  • Otomasyon: Instance yönetimini otomatikleştirin
  • Maliyet Tasarrufu: Kullanılmayan instance'ları durdurun
  • Kontrol: Instance'ları merkezi olarak yönetin

Nasıl Kullanılır?

Adım Adım Kullanım Kılavuzu

1. AWS CLI Yapılandırması

aws configure

2. Instance'ları Listele

./ec2_manager.sh list

3. Instance Başlat

./ec2_manager.sh start i-1234567890abcdef0

4. Instance Durdur

./ec2_manager.sh stop i-1234567890abcdef0

Gereksinimler

Gereksinimler

  • AWS CLI: AWS komut satırı aracı
  • AWS Credentials: AWS erişim anahtarları
  • EC2 Permissions: EC2 yönetim izinleri

Kullanım Senaryoları

Kullanım Senaryoları

1. Instance Yönetimi

EC2 instance'larını merkezi olarak yönetin.

2. Maliyet Optimizasyonu

Kullanılmayan instance'ları otomatik durdurun.

Örnekler

Kullanım Örnekleri

Örnek 1: Instance Listeleme

./ec2_manager.sh list

Örnek 2: Instance Başlatma

./ec2_manager.sh start i-1234567890abcdef0

Kod

#!/bin/bash

# AWS EC2 Instance Manager

ACTION="${1:-list}"

if ! command -v aws &> /dev/null; then
    echo "Error: AWS CLI not installed"
    exit 1
fi

case "$ACTION" in
    list)
        echo "======================================"
        echo "   EC2 INSTANCES"
        echo "======================================"
        aws ec2 describe-instances --query "Reservations[*].Instances[*].[InstanceId,State.Name,InstanceType,PublicIpAddress,PrivateIpAddress]" --output table
        ;;
    start)
        if [ -z "$2" ]; then
            echo "Usage: $0 start <instance-id>"
            exit 1
        fi
        echo "Starting instance: $2"
        aws ec2 start-instances --instance-ids "$2"
        ;;
    stop)
        if [ -z "$2" ]; then
            echo "Usage: $0 stop <instance-id>"
            exit 1
        fi
        echo "Stopping instance: $2"
        aws ec2 stop-instances --instance-ids "$2"
        ;;
    restart)
        if [ -z "$2" ]; then
            echo "Usage: $0 restart <instance-id>"
            exit 1
        fi
        echo "Restarting instance: $2"
        aws ec2 reboot-instances --instance-ids "$2"
        ;;
    *)
        echo "Usage: $0 [list|start|stop|restart] [instance-id]"
        exit 1
        ;;
esac

Kullanım

chmod +x ec2_manager.sh
./ec2_manager.sh list
./ec2_manager.sh start <instance-id>
./ec2_manager.sh stop <instance-id>

Sorun Giderme

Sorun Giderme

Problem: "Unable to locate credentials"

Çözüm: AWS credentials yapılandırın:

aws configure

Etiketler

aws ec2 cloud instance vm