

# 스팟 인스턴스 요청 태깅
<a name="concepts-spot-instances-request-tags"></a>

스팟 인스턴스 요청을 쉽게 분류하고 관리하려면 사용자 지정 메타데이터로 이 요청을 태깅할 수 있습니다. 스팟 인스턴스 요청을 생성할 때 또는 생성한 후 스팟 인스턴스 요청에 태그를 할당할 수 있습니다. Amazon EC2 콘솔이나 명령줄 도구를 사용하여 태그를 지정할 수 있습니다.

스팟 인스턴스 요청을 태깅하는 경우 스팟 인스턴스 요청에서 시작된 인스턴스 및 볼륨은 자동으로 태깅되지 않습니다. 스팟 인스턴스 요청에서 시작된 인스턴스 및 볼륨을 명시적으로 태깅해야 합니다. 시작 중 또는 이후에 스팟 인스턴스 및 볼륨에 태그를 할당할 수 있습니다.

태그 작동 방식에 대한 자세한 내용은 [Amazon EC2 리소스 태깅](Using_Tags.md) 섹션을 참조하세요.

**Topics**
+ [사전 조건](#tag-spot-request-prereqs)
+ [새 스팟 인스턴스 요청을 태깅하려면](#tag-new-spot-instance-request)
+ [기존 스팟 인스턴스 요청을 태깅하려면](#tag-existing-spot-instance-request)
+ [스팟 인스턴스 요청 태그 보기](#view-spot-instance-request-tags)

## 사전 조건
<a name="tag-spot-request-prereqs"></a>

사용자에게 리소스에 태그를 지정할 수 있는 권한을 부여합니다. IAM 정책 및 예제 정책에 대한 자세한 내용은 [예: 태그 리소스](ExamplePolicies_EC2.md#iam-example-taggingresources) 섹션을 참조하세요.

생성하는 IAM 정책은 스팟 인스턴스 요청을 생성할 때 사용하는 방법에 따라 결정됩니다.
+ 인스턴스 시작 마법사 또는 `run-instances`를 사용하여 스팟 인스턴스를 요청하는 경우 [To grant a user the permission to tag resources when using the launch instance wizard or run-instances](#iam-run-instances) 섹션을 참조하세요.
+ `request-spot-instances` 명령을 사용하여 스팟 인스턴스를 요청하는 방법에 대한 자세한 내용은 [To grant a user the permission to tag resources when using request-spot-instances](#iam-request-spot-instances) 섹션을 참조하세요.

**사용자에게 인스턴스 시작 마법사 또는 run-instances를 사용할 때 리소스에 태그를 지정할 수 있는 권한 부여**  
다음을 포함하는 IAM 정책을 만듭니다.
+ `ec2:RunInstances` 작업 사용자에게 인스턴스 시작 권한이 부여됩니다.
+ `Resource`에 `spot-instances-request`을 지정합니다. 이렇게 하면 사용자가 스팟 인스턴스를 요청하는 스팟 인스턴스 요청을 생성할 수 있습니다.
+ `ec2:CreateTags` 작업 사용자에게 태그 생성 권한이 부여됩니다.
+ `Resource`에 `*`을 지정합니다. 이를 통해 사용자가 인스턴스 시작 중에 생성된 모든 리소스에 태그를 지정할 수 있습니다.

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AllowLaunchInstances",
            "Effect": "Allow",
            "Action": [
                "ec2:RunInstances"
            ],
            "Resource": [
                "arn:aws:ec2:us-east-1::image/*",
                "arn:aws:ec2:us-east-1:*:subnet/*",
                "arn:aws:ec2:us-east-1:*:network-interface/*",
                "arn:aws:ec2:us-east-1:*:security-group/*",
                "arn:aws:ec2:us-east-1:*:key-pair/*",
                "arn:aws:ec2:us-east-1:*:volume/*",
                "arn:aws:ec2:us-east-1:*:instance/*",
                "arn:aws:ec2:us-east-1:*:spot-instances-request/*"
            ]
        },
        {
            "Sid": "TagSpotInstanceRequests",
            "Effect": "Allow",
            "Action": "ec2:CreateTags",
            "Resource": "*"
        }
    ]
}
```

------

RunInstances 작업을 사용하여 스팟 인스턴스 요청을 생성하고 생성 시 스팟 인스턴스 요청을 태깅하는 경우 Amazon EC2가 RunInstances 문에서 `spot-instances-request` 리소스를 평가하는 방법을 알고 있어야 합니다. 이는 IAM 정책에서 다음과 같이 평가됩니다.
+ 생성 시 스팟 인스턴스 요청을 태깅하지 않으면 Amazon EC2가 RunInstances 문에서 `spot-instances-request` 리소스를 평가하지 않습니다.
+ 생성 시 스팟 인스턴스 요청을 태깅하면 Amazon EC2가 RunInstances 문에서 `spot-instances-request` 리소스를 평가합니다.

따라서 `spot-instances-request` 리소스의 경우 IAM 정책에 다음 규칙이 적용됩니다.
+ RunInstances를 사용하여 스팟 인스턴스 요청을 생성하고 생성 시 스팟 인스턴스 요청을 태깅하지 않으려는 경우 `spot-instances-request` 리소스를 명시적으로 허용할 필요가 없습니다. 호출이 성공합니다.
+ RunInstances를 사용하여 스팟 인스턴스 요청을 생성하고 생성 시 스팟 인스턴스 요청을 태깅하려는 경우 RunInstances allow 문에 `spot-instances-request` 리소스를 포함해야 합니다. 그러지 않으면 호출이 실패합니다.
+ RunInstances를 사용하여 스팟 인스턴스 요청을 생성하고 생성 시 스팟 인스턴스 요청을 태깅하려는 경우 CreateTags allow 문에서 `spot-instances-request` 리소스를 지정하거나 `*` 와일드카드를 포함해야 합니다. 그러지 않으면 호출이 실패합니다.

스팟 인스턴스 요청에 지원되지 않는 정책을 포함한 예제 IAM 정책은 [스팟 인스턴스 작업](ExamplePolicies_EC2.md#iam-example-spot-instances) 섹션을 참조하세요.

**사용자에게 request-spot-instances를 사용할 때 리소스에 태그를 지정할 수 있는 권한 부여**  
다음을 포함하는 IAM 정책을 만듭니다.
+ `ec2:RequestSpotInstances` 작업 사용자에게 스팟 인스턴스 요청을 생성할 수 있는 권한이 부여됩니다.
+ `ec2:CreateTags` 작업 사용자에게 태그 생성 권한이 부여됩니다.
+ `Resource`에 `spot-instances-request`을 지정합니다. 이렇게 하면 사용자가 스팟 인스턴스 요청만 태깅할 수 있습니다.

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "TagSpotInstanceRequest",
            "Effect": "Allow",
            "Action": [
                "ec2:RequestSpotInstances",
                "ec2:CreateTags"
            ],
            "Resource": "arn:aws:ec2:us-east-1:111122223333:spot-instances-request/*"
        }
    ]
}
```

------

## 새 스팟 인스턴스 요청을 태깅하려면
<a name="tag-new-spot-instance-request"></a>

AWS CLI 및 PowerShell 예제에서 스팟 인스턴스 요청을 다음과 같이 구성합니다.
+ `ResourceType`에 `spot-instances-request`을 지정합니다. 다른 값을 지정하면 스팟 인스턴스 요청이 실패합니다.
+ `Tags`에 대해 키-값 페어를 지정합니다. 둘 이상의 키-값 페어를 지정할 수 있습니다.

------
#### [ Console ]

**새 스팟 인스턴스 요청에 태그를 지정하는 방법**

1. [스팟 인스턴스 관리](using-spot-instances-request.md)의 절차를 따르세요.

1. 태그를 추가하려면 **태그 추가** 페이지에서 **태그 추가**를 선택하고 해당 태그에 대한 키와 값을 입력합니다. 각 추가 태그에 **다른 태그 추가**를 선택합니다.

   각 태그에 대해 동일한 태그로 스팟 인스턴스 요청, 스팟 인스턴스 및 볼륨을 태깅할 수 있습니다. 세 가지 모두를 태깅하려면 [**인스턴스(Instances)**], [**볼륨(Volumes)**] 및 [**스팟 인스턴스 요청(Spot Instance Requests)**]이 선택되어 있는지 확인합니다. 한두 개만 태그를 지정하려면 태그를 지정할 리소스가 선택되어 있고 나머지 리소스는 선택 취소되어 있는지 확인합니다.

1. 필수 필드를 입력하여 스팟 인스턴스 요청을 생성한 다음 [**시작(Launch)**]을 선택합니다. 자세한 내용은 [스팟 인스턴스 관리](using-spot-instances-request.md) 섹션을 참조하세요.

------
#### [ AWS CLI ]

**새 스팟 인스턴스 요청에 태그를 지정하는 방법**  
[request-spot-instances](https://docs.aws.amazon.com/cli/latest/reference/ec2/request-spot-instances.html) 명령을 `--tag-specification` 옵션과 함께 사용합니다.

태그 사양은 스팟 인스턴스 요청에 `Environment=Production` 및 `Cost-Center=123`이라는 2개의 태그를 추가합니다.

```
aws ec2 request-spot-instances \
    --instance-count 5 \
    --type "one-time" \
    --launch-specification file://specification.json \
    --tag-specification 'ResourceType=spot-instances-request,Tags=[{Key=Environment,Value=Production},{Key=Cost-Center,Value=123}]'
```

------
#### [ PowerShell ]

**새 스팟 인스턴스 요청에 태그를 지정하는 방법**  
[Request-EC2SpotInstance](https://docs.aws.amazon.com/powershell/latest/reference/items/Request-EC2SpotInstance.html) cmdlet을 `-TagSpecification` 파라미터와 함께 사용합니다.

```
-TagSpecification $tagspec
```

태그 사양은 다음과 같이 정의됩니다. 스팟 인스턴스 요청에 `Environment=Production` 및 `Cost-Center=123`이라는 2개의 태그를 추가합니다.

```
$tag1 = @{Key="Environment"; Value="Production"}
$tag2 = @{Key="Cost-Center"; Value="123"}
$tagspec = New-Object Amazon.EC2.Model.TagSpecification
$tagspec.ResourceType = "spot-instances-request"
$tagspec.Tags = @($tag1,$tag2)
```

------

## 기존 스팟 인스턴스 요청을 태깅하려면
<a name="tag-existing-spot-instance-request"></a>

------
#### [ Console ]

**기존 스팟 인스턴스 요청에 태그를 지정하는 방법**

스팟 인스턴스 요청을 생성한 후 콘솔을 사용하여 스팟 인스턴스 요청에 태그를 추가할 수 있습니다.

1. [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/)에서 Amazon EC2 콘솔을 엽니다.

1. 탐색 창에서 **스팟 요청**을 선택합니다.

1. 스팟 인스턴스 요청을 선택합니다.

1. **태그** 탭을 선택하고 **태그 생성**을 선택합니다.

**콘솔을 사용하여 기존 스팟 인스턴스를 태깅하려면**  
스팟 인스턴스 요청에서 스팟 인스턴스가 시작된 후 콘솔을 사용하여 인스턴스에 태그를 추가할 수 있습니다. 자세한 내용은 [콘솔을 사용하여 태그 추가](Using_Tags_Console.md#adding-or-deleting-tags) 섹션을 참조하세요.

------
#### [ AWS CLI ]

**기존 스팟 인스턴스 요청 또는 스팟 인스턴스에 태그를 지정하려면**  
[create-tags](https://docs.aws.amazon.com/cli/latest/reference/ec2/create-tags.html) 명령을 사용하여 기존 리소스에 태그를 지정합니다. 다음 예제에서는 기존 스팟 인스턴스 요청 및 스팟 인스턴스에 `purpose=test` 태그가 지정됩니다.

```
aws ec2 create-tags \
    --resources sir-0e54a519c9EXAMPLE i-1234567890abcdef0 \
    --tags Key=purpose,Value=test
```

------
#### [ PowerShell ]

**기존 스팟 인스턴스 요청 또는 스팟 인스턴스에 태그를 지정하려면**  
[New-EC2Tag](https://docs.aws.amazon.com/powershell/latest/reference/items/New-EC2Tag.html) cmdlet을 사용합니다. 다음 예제는 기존 스팟 인스턴스 요청 및 스팟 인스턴스에 `purpose=test` 태그를 추가합니다.

```
New-EC2Tag `
    -Resource sir-0e54a519c9EXAMPLE, i-1234567890abcdef0 `
    -Tag @{Key="purpose"; Value="test"}
```

------

## 스팟 인스턴스 요청 태그 보기
<a name="view-spot-instance-request-tags"></a>

------
#### [ Console ]

**스팟 인스턴스 요청 태그를 보는 방법**

1. [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/)에서 Amazon EC2 콘솔을 엽니다.

1. 탐색 창에서 **스팟 요청**을 선택합니다.

1. 스팟 인스턴스 요청을 선택하고 [**태그(Tags)**] 탭을 선택합니다.

------
#### [ AWS CLI ]

**스팟 인스턴스 요청 태그를 설명하려면**  
[describe-spot-instance-requests](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-spot-instance-requests.html) 명령을 사용하여 지정된 스팟 인스턴스 요청의 구성을 볼 수 있습니다. 여기에는 요청에 지정된 모든 태그가 포함됩니다.

```
aws ec2 describe-spot-instance-requests \
    --spot-instance-request-ids sir-0e54a519c9EXAMPLE \
    --query "SpotInstanceRequests[*].Tags"
```

다음은 예제 출력입니다.

```
[
    [
        {
            "Key": "Environment",
            "Value": "Production"
        },
        {
            "Key": "Department",
            "Value": "101"
        }
    ]
]
```

------
#### [ PowerShell ]

**스팟 인스턴스 요청 태그를 설명하려면**  
[Get-EC2SpotInstanceRequest](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2SpotInstanceRequest.html) cmdlet을 사용합니다.

```
(Get-EC2SpotInstanceRequest `
    -SpotInstanceRequestId sir-0e54a519c9EXAMPLE).Tags
```

다음은 예제 출력입니다.

```
Key         Value
---         -----
Environment Production
Department  101
```

------