AWS SAA 学習ノート: EC2 (Hibernate)
EC2ハイバネーション学習ノート
概要
EC2 Hibernate - EC2ハイバネーション
A feature that saves the contents of RAM to Amazon EBS root volume when an instance is stopped, allowing faster startup times when the instance is restarted.
インスタンスが停止されるときにRAMの内容をAmazon EBSルートボリュームに保存し、インスタンス再起動時により高速な起動を可能にする機能。
これはなんでしょう?
通常の停止/開始 vs ハイバネーション
- Normal Stop: RAM is cleared, OS and applications restart from scratch - 通常の停止:RAMがクリアされ、OSとアプリケーションが最初から再起動
- Hibernate: RAM contents saved to EBS, restored on restart - ハイバネーション:RAMの内容がEBSに保存され、再起動時に復元
プロセスフロー
- Instance hibernation triggered - インスタンスのハイバネーションがトリガー
- RAM contents written to EBS root volume - RAMの内容がEBSルートボリュームに書き込み
- Instance stopped - インスタンス停止
- On restart, RAM contents restored from EBS - 再起動時、EBSからRAMの内容を復元
- Applications resume from previous state - アプリケーションが前の状態から再開
要件と制限
サポートされるインスタンスタイプ
- General Purpose: M3, M4, M5, M5a, M5ad, M5d, M5dn, M5n, M5zn
- Compute Optimized: C3, C4, C5, C5d, C5n
- Memory Optimized: R3, R4, R5, R5a, R5ad, R5d, R5dn, R5n
- Storage Optimized: I3, I3en
- Accelerated Computing: P2, P3, P4
インスタンスサイズの制限
- Maximum RAM: 150 GB - 最大RAM:150GB
- Hibernation not supported for instances with more than 150 GB RAM - 150GB以上のRAMを持つインスタンスではハイバネーションはサポートされない
ストレージ要件
- Root Volume: Must be EBS (not instance store) - ルートボリューム:EBSである必要がある(インスタンスストアは不可)
- Volume Type: gp2, gp3, io1, io2 supported - ボリュームタイプ:gp2、gp3、io1、io2がサポート
- Encryption: Root volume must be encrypted - 暗号化:ルートボリュームは暗号化されている必要がある
- Size: Root volume must be large enough to store RAM contents - サイズ:RAMの内容を保存するのに十分な大きさが必要
オペレーティングシステムサポート
- Amazon Linux 2 - Amazon Linux 2
- Amazon Linux AMI - Amazon Linux AMI
- Ubuntu 18.04 LTS and later - Ubuntu 18.04 LTS以降
- Windows Server 2016 and later - Windows Server 2016以降
- CentOS 8 and later - CentOS 8以降
- Red Hat Enterprise Linux 8 and later - Red Hat Enterprise Linux 8以降
設定
ハイバネーションの有効化
- Must be enabled at instance launch - インスタンス起動時に有効化する必要がある
- Cannot be enabled on existing instances - 既存のインスタンスでは有効化不可
- Hibernate agent must be installed on the instance - インスタンスにハイバネーションエージェントがインストールされている必要がある
IAM権限
Required permissions for hibernation - ハイバネーションに必要な権限:
ec2:StopInstances
- インスタンス停止権限ec2:StartInstances
- インスタンス開始権限ec2:CreateSnapshot
- スナップショット作成権限ec2:CreateTags
- タグ作成権限
使用例
長時間実行プロセス
- Data Analysis: Resume complex calculations without losing progress - データ分析:進行状況を失うことなく複雑な計算を再開
- Machine Learning: Continue training models from previous state - 機械学習:前の状態からモデルのトレーニングを継続
- Batch Processing: Resume batch jobs without restarting - バッチ処理:再起動せずにバッチジョブを再開
開発とテスト
- Development Environments: Quickly resume development work - 開発環境:開発作業を迅速に再開
- Testing: Maintain test state across multiple sessions - テスト:複数のセッション間でテスト状態を維持
コスト最適化
- Scheduled Workloads: Stop instances during off-hours, resume quickly - スケジュールされたワークロード:営業時間外にインスタンスを停止し、迅速に再開
- Resource Management: Avoid long boot times for frequently used instances - リソース管理:頻繁に使用するインスタンスの長いブート時間を回避
メリット
パフォーマンス
- Faster Startup: Skip OS boot and application initialization - 高速起動:OSブートとアプリケーション初期化をスキップ
- State Preservation: Applications resume exactly where they left off - 状態保持:アプリケーションが中断した地点から正確に再開
- Reduced Initialization Time: No need to reload data or reconfigure applications - 初期化時間の短縮:データの再読み込みやアプリケーションの再設定が不要
コスト
- Pay Only When Running: No charges when hibernated (only EBS storage costs) - 実行時のみ課金:ハイバネーション中は課金されない(EBSストレージコストのみ)
- Efficient Resource Usage: Optimize instance usage patterns - 効率的なリソース使用:インスタンス使用パターンの最適化
要注意!!!!
時間制限
- Maximum Hibernation Duration: 60 days - 最大ハイバネーション期間:60日
- Instance will be terminated if hibernated longer than 60 days - 60日を超えてハイバネーションされると、インスタンスは終了される
ネットワークとセキュリティ
- IP Addresses: Public IP addresses may change (use Elastic IP for consistency) - IPアドレス:パブリックIPアドレスが変更される可能性(一貫性のためにElastic IPを使用)
- Security Groups: Remain attached but may need verification - セキュリティグループ:アタッチされたままだが検証が必要な場合がある
インスタンスストアの制限
- Data Loss: Instance store data is lost during hibernation - データ損失:ハイバネーション中にインスタンスストアデータが失われる
- Not Supported: Instances with instance store volumes cannot be hibernated - サポートされない:インスタンスストアボリュームを持つインスタンスはハイバネーション不可
どうしたらいい?!
Planning and Design - 計画と設計
- Enable at Launch: Plan hibernation requirements before instance creation - 起動時に有効化:インスタンス作成前にハイバネーション要件を計画
- Storage Sizing: Ensure EBS root volume is large enough for RAM + OS - ストレージサイジング:EBSルートボリュームがRAM + OSに十分な大きさであることを確認
- Use Elastic IP: Assign Elastic IP addresses for consistent network access - Elastic IPの使用:一貫したネットワークアクセスのためにElastic IPアドレスを割り当て
Monitoring and Management - モニタリングと管理
- CloudWatch Metrics: Monitor hibernation events and performance - CloudWatchメトリクス:ハイバネーションイベントとパフォーマンスを監視
- Automation: Use Auto Scaling and Lambda for automated hibernation - 自動化:自動ハイバネーションのためにAuto ScalingとLambdaを使用
- Testing: Test hibernation and resume processes regularly - テスト:ハイバネーションと再開プロセスを定期的にテスト
よくある問題!
Hibernation Fails - ハイバネーション失敗
- Check: Instance type and size compatibility - 確認:インスタンスタイプとサイズの互換性
- Verify: EBS root volume encryption and size - 検証:EBSルートボリュームの暗号化とサイズ
- Review: Hibernation agent installation and configuration - レビュー:ハイバネーションエージェントのインストールと設定
Resume Issues - 再開問題
- Network: Verify security group and network ACL configurations - ネットワーク:セキュリティグループとネットワークACL設定を確認
- Applications: Check application state and connectivity - アプリケーション:アプリケーションの状態と接続性を確認
- Logs: Review system and application logs for errors - ログ:エラーについてシステムとアプリケーションログを確認
ポイント
- Must be enabled at instance launch - インスタンス起動時に有効化が必要
- Requires encrypted EBS root volume - 暗号化されたEBSルートボリュームが必要
- Maximum 150 GB RAM and 60-day hibernation limit - 最大150GBのRAMと60日のハイバネーション制限
- Preserves RAM state for faster startup - より高速な起動のためにRAM状態を保持
- Cost-effective for intermittent workloads - 断続的なワークロードに対してコスト効率的
- Public IP addresses may change without Elastic IP - Elastic IPなしではパブリックIPアドレスが変更される可能性