Amazon EC2 인스턴스 최대 절전(Hibernation) 활성화하기

Amazon EC2 인스턴스 최대 절전(Hibernation) 활성화하기

인스턴스를 최대 절전하려면 인스턴스를 시작하면서 최대 절전을 활성화해야 해요. 이 글에서는 On-Demand 인스턴스와 Spot 인스턴스에서 최대 절전을 활성화하는 방법과, 인스턴스가 최대 절전으로 활성화되었는지 확인하는 방법을 살펴볼게요.

출처: 문서

본문

인스턴스를 최대 절전(hibernate)하려면 인스턴스를 시작하면서 먼저 최대 절전을 활성화해야 해요.

Important
인스턴스를 시작한 뒤에는 최대 절전을 활성화하거나 비활성화할 수 없어요.

On-Demand 인스턴스에서 최대 절전 활성화하기 (Enable hibernation for On-Demand Instances)

On-Demand 인스턴스에서 최대 절전을 활성화할 수 있어요.

콘솔 (Console)

On-Demand 인스턴스에서 최대 절전을 활성화하려면

  1. Amazon EC2 콘솔에서 런치 인스턴스 마법사를 엽니다.
  2. 스토리지(Storage) 구성에서 최대 절전을 지원하는 AMI를 선택하고, EBS 루트 볼륨을 다음 요구사항으로 구성해요. (지원 AMI와 인스턴스 패밀리에 대한 자세한 내용은 Prerequisites for EC2 instance hibernation 참고)
    • Size (GiB): EBS 루트 볼륨 크기를 입력해요. 볼륨은 RAM 내용을 저장하고 예상 사용량을 수용할 만큼 충분히 커야 해요.
    • Volume type: 지원되는 EBS 볼륨 유형(General Purpose SSD gp2·gp3 또는 Provisioned IOPS SSD io1·io2)을 선택해요.
    • Encrypted: Yes를 선택해요. 이 AWS 리전에서 기본적으로 암호화를 활성화했다면 Yes가 선택되어 있어요.
    • KMS key: 볼륨의 암호화 키를 선택해요. 이 AWS 리전에서 기본적으로 암호화를 활성화했다면 기본 암호화 키가 선택됩니다.
  3. Advanced details를 펼치고 Stop - Hibernate behavior에서 Enable을 선택해요.
  4. Summary 패널에서 인스턴스 구성을 검토하고 Launch instance를 선택해요.

AWS CLI

On-Demand 인스턴스에서 최대 절전을 활성화하려면

run-instances 명령을 사용해 인스턴스를 시작해요. --block-device-mappings file://mapping.json 파라미터로 EBS 루트 볼륨 파라미터를 지정하고, --hibernation-options Configured=true 파라미터로 최대 절전을 활성화해요.

aws ec2 run-instances \
    --image-id ami-0abcdef1234567890 \
    --instance-type m5.large \
    --block-device-mappings file://mapping.json \
    --hibernation-options Configured=true \
    --count 1 \
    --key-name MyKeyPair

mapping.json에 다음을 지정해요.

[
    {
        "DeviceName": "/dev/xvda",
        "Ebs": {
            "VolumeSize": 30,
            "VolumeType": "gp2",
            "Encrypted": true
        }
    }
]

DeviceName의 값은 AMI와 연결된 루트 디바이스 이름과 일치해야 해요. 루트 디바이스 이름을 찾으려면 describe-images 명령을 사용해요.

aws ec2 describe-images --image-id ami-0abcdef1234567890

이 AWS 리전에서 기본적으로 암호화를 활성화했다면 "Encrypted": true를 생략할 수 있어요.

PowerShell

On-Demand 인스턴스에서 최대 절전을 활성화하려면

New-EC2Instance 명령을 사용해 인스턴스를 시작해요. 먼저 블록 디바이스 매핑을 정의해 EBS 루트 볼륨을 지정한 뒤 -BlockDeviceMappings 파라미터로 명령에 추가해요. -HibernationOptions_Configured $true 파라미터로 최대 절전을 활성화해요.

$ebs_encrypt = New-Object Amazon.EC2.Model.BlockDeviceMapping
$ebs_encrypt.DeviceName = "/dev/xvda"
$ebs_encrypt.Ebs = New-Object Amazon.EC2.Model.EbsBlockDevice
$ebs_encrypt.Ebs.VolumeSize = 30
$ebs_encrypt.Ebs.VolumeType = "gp2"
$ebs_encrypt.Ebs.Encrypted = $true

New-EC2Instance `
    -ImageId ami-0abcdef1234567890 `
    -InstanceType m5.large `
    -BlockDeviceMappings $ebs_encrypt `
    -HibernationOptions_Configured $true `
    -MinCount 1 `
    -MaxCount 1 `
    -KeyName MyKeyPair

DeviceName의 값은 AMI와 연결된 루트 디바이스 이름과 일치해야 해요. 루트 디바이스 이름을 찾으려면 Get-EC2Image 명령을 사용해요.

Get-EC2Image -ImageId ami-0abcdef1234567890

이 AWS 리전에서 기본적으로 암호화를 활성화했다면 블록 디바이스 매핑에서 Encrypted = $true를 생략할 수 있어요.

Spot 인스턴스에서 최대 절전 활성화하기 (Enable hibernation for Spot Instances)

Spot 인스턴스에서 최대 절전을 활성화할 수 있어요. 중단 시 Spot 인스턴스를 최대 절전하는 방법에 대한 자세한 내용은 Spot Instance interruptions를 참고하세요.

콘솔 (Console)

Spot 인스턴스에서 최대 절전을 활성화하려면

  1. Amazon EC2 콘솔에서 런치 인스턴스 마법사를 엽니다. (Spot 인스턴스 요청 방법은 Create a Spot Instance request 참고)
  2. 스토리지 구성에서 최대 절전을 지원하는 AMI를 선택하고, EBS 루트 볼륨을 다음 요구사항으로 구성해요. (지원 AMI와 인스턴스 패밀리에 대한 자세한 내용은 Prerequisites for EC2 instance hibernation 참고)
    • Size (GiB): EBS 루트 볼륨 크기를 입력해요. 볼륨은 RAM 내용을 저장하고 예상 사용량을 수용할 만큼 충분히 커야 해요.
    • Volume type: 지원되는 EBS 볼륨 유형(General Purpose SSD gp2·gp3 또는 Provisioned IOPS SSD io1·io2)을 선택해요.
    • Encrypted: Yes를 선택해요.
    • KMS key: 볼륨의 암호화 키를 선택해요.
  3. Request type에서 Persistent를 선택해요.
  4. Interruption behavior에서 Hibernate를 선택하거나, 대안으로 Stop - Hibernate behavior에서 Enable을 선택해요. 두 필드 모두 Spot 인스턴스의 최대 절전을 활성화합니다. 둘 중 하나만 구성하면 돼요.
  5. Summary 패널에서 인스턴스 구성을 검토하고 Launch instance를 선택해요.

AWS CLI

Spot 인스턴스에서 최대 절전을 활성화하려면

run-instances 명령을 사용해 Spot 인스턴스를 요청해요. --block-device-mappings file://mapping.json 파라미터로 EBS 루트 볼륨 파라미터를 지정하고, --hibernation-options Configured=true 파라미터로 최대 절전을 활성화해요. Spot 요청 유형(SpotInstanceType)은 persistent여야 해요.

aws ec2 run-instances \
    --image-id ami-0abcdef1234567890 \
    --instance-type c4.xlarge \
    --block-device-mappings file://mapping.json \
    --hibernation-options Configured=true \
    --count 1 \
    --key-name MyKeyPair
    --instance-market-options
        {
           "MarketType":"spot",
           "SpotOptions":{
              "MaxPrice":"1",
              "SpotInstanceType":"persistent"
            }
        }

mapping.json에 EBS 루트 볼륨 파라미터를 다음과 같이 지정해요.

[
    {
        "DeviceName": "/dev/xvda",
        "Ebs": {
            "VolumeSize": 30,
            "VolumeType": "gp2",
            "Encrypted": true
        }
    }
]

DeviceName의 값은 AMI와 연결된 루트 디바이스 이름과 일치해야 해요. 루트 디바이스 이름을 찾으려면 describe-images 명령을 사용해요.

aws ec2 describe-images --image-id ami-0abcdef1234567890

이 AWS 리전에서 기본적으로 암호화를 활성화했다면 "Encrypted": true를 생략할 수 있어요.

PowerShell

Spot 인스턴스에서 최대 절전을 활성화하려면

New-EC2Instance 명령을 사용해 Spot 인스턴스를 요청해요. 먼저 블록 디바이스 매핑을 정의해 EBS 루트 볼륨을 지정한 뒤 -BlockDeviceMappings 파라미터로 명령에 추가해요. -HibernationOptions_Configured $true 파라미터로 최대 절전을 활성화해요.

$ebs_encrypt = New-Object Amazon.EC2.Model.BlockDeviceMapping
$ebs_encrypt.DeviceName = "/dev/xvda"
$ebs_encrypt.Ebs = New-Object Amazon.EC2.Model.EbsBlockDevice
$ebs_encrypt.Ebs.VolumeSize = 30
$ebs_encrypt.Ebs.VolumeType = "gp2"
$ebs_encrypt.Ebs.Encrypted = $true

New-EC2Instance `
    -ImageId ami-0abcdef1234567890 `
    -InstanceType m5.large `
    -BlockDeviceMappings $ebs_encrypt `
    -HibernationOptions_Configured $true `
    -MinCount 1 `
    -MaxCount 1 `
    -KeyName MyKeyPair `
    -InstanceMarketOption @(
        MarketType = spot;
        SpotOptions @{
        MaxPrice = 1;
        SpotInstanceType = persistent}
    )

DeviceName의 값은 AMI와 연결된 루트 디바이스 이름과 일치해야 해요. 루트 디바이스 이름을 찾으려면 Get-EC2Image 명령을 사용해요.

Get-EC2Image -ImageId ami-0abcdef1234567890

이 AWS 리전에서 기본적으로 암호화를 활성화했다면 블록 디바이스 매핑에서 Encrypted = $true를 생략할 수 있어요.

인스턴스가 최대 절전으로 활성화되었는지 확인하기 (View if an instance is enabled for hibernation)

인스턴스가 최대 절전으로 활성화되어 있는지 확인할 수 있어요.

콘솔 (Console)

인스턴스가 최대 절전으로 활성화되어 있는지 확인하려면

  1. Amazon EC2 콘솔을 엽니다: https://console.aws.amazon.com/ec2/
  2. 탐색 창에서 Instances를 선택해요.
  3. 인스턴스를 선택하고 Details 탭의 Instance details 섹션에서 Stop-hibernate behavior를 확인해요. Enabled이면 인스턴스가 최대 절전으로 활성화된 것입니다.

AWS CLI

인스턴스가 최대 절전으로 활성화되어 있는지 확인하려면

describe-instances 명령을 사용하고 --filters "Name=hibernation-options.configured,Values=true" 파라미터로 최대 절전으로 활성화된 인스턴스를 필터링해요.

aws ec2 describe-instances \
    --filters "Name=hibernation-options.configured,Values=true"

출력의 다음 필드는 인스턴스가 최대 절전으로 활성화되어 있음을 나타냅니다.

"HibernationOptions": {
    "Configured": true
}

PowerShell

인스턴스가 최대 절전으로 활성화되어 있는지 확인하려면

Get-EC2Instance cmdlet을 사용해 최대 절전으로 활성화된 인스턴스를 필터링해요.

(Get-EC2Instance `
    -Filter @{Name="hibernation-options.configured"; Values="true"}).Instances

더 알아보기 (Learn more)