CLI로 RequestSpotFleet 사용 - Amazon Elastic Compute Cloud

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

CLI로 RequestSpotFleet 사용

다음 코드 예제는 RequestSpotFleet의 사용 방법을 보여 줍니다.

CLI
AWS CLI

서브넷에서 가장 저렴한 가격으로 스팟 플릿 요청

이 예시 명령은 서브넷만 다른 두 가지 출시 사양을 가진 스팟 플릿 요청을 생성합니다. 스팟 플릿은 지정된 서브넷에서 가장 낮은 가격으로 인스턴스를 시작합니다. 인스턴스가 기본 VPC로 시작되는 경우, 인스턴스는 기본적으로 퍼블릭 IP 주소를 받습니다. 인스턴스가 기본이 아닌 VPC로 시작되는 경우, 인스턴스는 기본적으로 퍼블릭 IP 주소를 받지 않습니다.

스팟 플릿 요청에서는 동일한 가용 영역에서 다른 서브넷을 지정할 수 없습니다.

명령:

aws ec2 request-spot-fleet --spot-fleet-request-config file://config.json

Config.json:

{ "SpotPrice": "0.04", "TargetCapacity": 2, "IamFleetRole": "arn:aws:iam::123456789012:role/my-spot-fleet-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "SecurityGroups": [ { "GroupId": "sg-1a2b3c4d" } ], "InstanceType": "m3.medium", "SubnetId": "subnet-1a2b3c4d, subnet-3c4d5e6f", "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" } } ] }

출력:

{ "SpotFleetRequestId": "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE" }

가용 영역에서 최저 가격으로 스팟 플릿 요청

이 예시 명령은 가용 영역만 다른 두 가지 출시 사양을 가진 스팟 플릿 요청을 생성합니다. 스팟 플릿은 지정된 가용 영역에서 가장 낮은 가격으로 인스턴스를 시작합니다. 계정이 EC2-VPC만 지원하는 경우, Amazon EC2는 가용 영역의 기본 서브넷에서 스팟 인스턴스를 실행합니다. 계정이 EC2-Classic을 지원하는 경우, Amazon EC2는 가용 영역의 EC2-Classic에서 인스턴스를 시작합니다.

명령:

aws ec2 request-spot-fleet --spot-fleet-request-config file://config.json

Config.json:

{ "SpotPrice": "0.04", "TargetCapacity": 2, "IamFleetRole": "arn:aws:iam::123456789012:role/my-spot-fleet-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "SecurityGroups": [ { "GroupId": "sg-1a2b3c4d" } ], "InstanceType": "m3.medium", "Placement": { "AvailabilityZone": "us-west-2a, us-west-2b" }, "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" } } ] }

서브넷에서 스팟 인스턴스를 시작하고 퍼블릭 IP 주소 할당

이 예시 명령은 기본값이 아닌 VPC에서 시작된 인스턴스에 퍼블릭 주소를 할당합니다. 네트워크 인터페이스를 지정할 때는 네트워크 인터페이스를 사용하는 서브넷 ID 및 보안 그룹 ID를 포함해야 합니다.

명령:

aws ec2 request-spot-fleet --spot-fleet-request-config file://config.json

Config.json:

{ "SpotPrice": "0.04", "TargetCapacity": 2, "IamFleetRole": "arn:aws:iam::123456789012:role/my-spot-fleet-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "InstanceType": "m3.medium", "NetworkInterfaces": [ { "DeviceIndex": 0, "SubnetId": "subnet-1a2b3c4d", "Groups": [ "sg-1a2b3c4d" ], "AssociatePublicIpAddress": true } ], "IamInstanceProfile": { "Arn": "arn:aws:iam::880185128111:instance-profile/my-iam-role" } } ] }

다양한 할당 전략을 사용하여 스팟 플릿 요청

이 예시 명령은 다양한 할당 전략을 사용하여 30개의 인스턴스를 실행하는 스팟 플릿 요청을 생성합니다. 시작 사양은 인스턴스 유형에 따라 다릅니다. 스팟 플릿은 각 유형에 10개의 인스턴스가 있도록 출시 사양에 따라 인스턴스를 배포합니다.

명령:

aws ec2 request-spot-fleet --spot-fleet-request-config file://config.json

Config.json:

{ "SpotPrice": "0.70", "TargetCapacity": 30, "AllocationStrategy": "diversified", "IamFleetRole": "arn:aws:iam::123456789012:role/my-spot-fleet-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "InstanceType": "c4.2xlarge", "SubnetId": "subnet-1a2b3c4d" }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "m3.2xlarge", "SubnetId": "subnet-1a2b3c4d" }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "r3.2xlarge", "SubnetId": "subnet-1a2b3c4d" } ] }

자세한 내용은 Amazon Elastic Compute Cloud 사용 설명서의 스팟 플릿 요청을 참조하세요.

  • API 세부 정보는 AWS CLI 명령 참조RequestSpotFleet 섹션을 참조하세요.

PowerShell
PowerShell용 도구

예제 1:이 예제에서는 지정된 인스턴스 유형에 대해 최저 가격으로 가용 영역에 스팟 플릿 요청을 생성합니다. 계정이 EC2-VPC만 지원하는 경우 스팟 플릿은 기본 서브넷이 있는 최저 가격의 가용 영역에서 인스턴스를 시작합니다. 계정이 EC2-Classic을 지원하는 경우 스팟 플릿은 최저 가격의 가용 영역에서 EC2-Classic의 인스턴스를 시작합니다. 지불하는 가격은 요청에 지정된 스팟 가격을 초과하지 않습니다.

$sg = New-Object Amazon.EC2.Model.GroupIdentifier $sg.GroupId = "sg-12345678" $lc = New-Object Amazon.EC2.Model.SpotFleetLaunchSpecification $lc.ImageId = "ami-12345678" $lc.InstanceType = "m3.medium" $lc.SecurityGroups.Add($sg) Request-EC2SpotFleet -SpotFleetRequestConfig_SpotPrice 0.04 ` -SpotFleetRequestConfig_TargetCapacity 2 ` -SpotFleetRequestConfig_IamFleetRole arn:aws:iam::123456789012:role/my-spot-fleet-role ` -SpotFleetRequestConfig_LaunchSpecification $lc
  • API 세부 정보는 AWS Tools for PowerShell Cmdlet 참조RequestSpotFleet을 참조하세요.

AWS SDK 개발자 안내서 및 코드 예제의 전체 목록은 섹션을 참조하세요를 사용하여 Amazon EC2 리소스 생성 AWS SDK. 이 주제에는 시작하기에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.