

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 自訂 EC2 執行個體的排程事件通知
<a name="customizing_scheduled_event_notifications"></a>

您可以自訂排程事件通知，以便在電子郵件通知中包含標籤。如此可以更輕鬆地識別受影響的資源 (執行個體或 專用執行個體)，並為即將到來的事件排定動作的優先順序。

當您自訂事件通知以包含標籤時，您可以選擇包含：
+ 與受影響資源關聯的所有標籤
+ 僅與受影響資源關聯的特定標籤

例如，假設您將 `application`、`costcenter`、`project`，和 `owner` 標籤指派給所有執行個體。您可以選擇在事件通知中包含所有標籤。或者，如果您只想在事件通知中看到 `owner` 和 `project` 標籤，則可以選擇只包含這些標籤。

選取要包含的標籤之後，事件通知將包含資源 ID (執行個體 ID 或 專用執行個體 ID)，以及與受影響資源關聯的標籤金鑰和值組。

**Topics**
+ [在事件通知中包含標籤](#register-tags)
+ [從事件通知中移除標籤](#deregister-tags)
+ [檢視要包含在事件通知中的標籤](#view-tags)

## 在事件通知中包含標籤
<a name="register-tags"></a>

您選擇要包含的標籤會套用至所選區域的所有資源 (執行個體和 專用執行個體)。若要自訂其他區域中的事件通知，請先選取所需的區域，然後執行下列步驟。

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

**在事件通知中包含標籤**

1. 在 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格中，選擇 **Events** (事件)。

1. 選擇 **Actions (動作)**、**Manage event notifications (管理事件通知)**。

1. 開啟**在事件通知中包含標籤**。

1. 根據您要包含在事件通知中的標籤，執行下列其中一項動作：
   + 若要包含與受影響執行個體或專用執行個體相關聯的所有標籤，請選取**包含所有資源標籤**。
   + 如需選取要包含的標籤，請選取**選擇要包含的標籤**，然後選取或輸入標籤索引鍵。

1. 選擇**儲存**。

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

**在事件通知中包含所有標籤**  
使用 [register-instance-event-notification-attributes](https://docs.aws.amazon.com/cli/latest/reference/ec2/register-instance-event-notification-attributes.html) 命令並將 `IncludeAllTagsOfInstance` 參數設定為 `true`。

```
aws ec2 register-instance-event-notification-attributes \
    --instance-tag-attribute "IncludeAllTagsOfInstance=true"
```

**在事件通知中包含特定標籤**  
使用 [register-instance-event-notification-attributes](https://docs.aws.amazon.com/cli/latest/reference/ec2/register-instance-event-notification-attributes.html) 命令，並使用 `InstanceTagKeys` 參數指定要包含的標籤。

```
aws ec2 register-instance-event-notification-attributes \
    --instance-tag-attribute 'InstanceTagKeys=["{{tag_key_1}}", "{{tag_key_2}}", "{{tag_key_3}}"]'
```

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

**在事件通知中包含所有標籤**  
使用 [Register-EC2InstanceEventNotificationAttribute](https://docs.aws.amazon.com/powershell/latest/reference/items/Register-EC2InstanceEventNotificationAttribute.html) cmdlet。

```
Register-EC2InstanceEventNotificationAttribute `
    -InstanceTagAttribute_IncludeAllTagsOfInstance $true
```

**在事件通知中包含特定標籤**  
使用 [Register-EC2InstanceEventNotificationAttribute](https://docs.aws.amazon.com/powershell/latest/reference/items/Register-EC2InstanceEventNotificationAttribute.html) cmdlet。

```
Register-EC2InstanceEventNotificationAttribute `
    -InstanceTagAttribute_InstanceTagKey {{tag_key_1}}, {{tag_key_2}}, {{tag_key_3}}
```

------

## 從事件通知中移除標籤
<a name="deregister-tags"></a>

可從事件通知中移除標籤。

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

**從事件通知中移除標籤**

1. 在 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格中，選擇 **Events** (事件)。

1. 選擇 **Actions (動作)**、**Manage event notifications (管理事件通知)**。

1. 若要從事件通知中移除所有標籤，請關閉**在事件通知中包含資源標籤**。

1. 若要從事件通知中移除特定標籤，請為對應的標籤索引鍵選擇 **X**)。

1. 選擇**儲存**。

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

**從事件通知中移除所有標籤**  
使用 [deregister-instance-event-notification-attributes](https://docs.aws.amazon.com/cli/latest/reference/ec2/deregister-instance-event-notification-attributes.html) 命令並將 `IncludeAllTagsOfInstance` 參數設定為 `false`。

```
aws ec2 deregister-instance-event-notification-attributes \
    --instance-tag-attribute "IncludeAllTagsOfInstance=false"
```

**從事件通知中移除標籤**  
使用 [deregister-instance-event-notification-attributes](https://docs.aws.amazon.com/cli/latest/reference/ec2/deregister-instance-event-notification-attributes.html) 命令，並使用 `InstanceTagKeys` 參數指定要移除的標籤。

```
aws ec2 deregister-instance-event-notification-attributes \
    --instance-tag-attribute 'InstanceTagKeys=["{{tag_key_3}}"]'
```

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

**從事件通知中移除所有標籤**  
使用 [Unregister-EC2InstanceEventNotificationAttribute](https://docs.aws.amazon.com/powershell/latest/reference/items/Unregister-EC2InstanceEventNotificationAttribute.html) cmdlet。

```
Unregister-EC2InstanceEventNotificationAttribute `
    -InstanceTagAttribute_IncludeAllTagsOfInstance $false
```

**從事件通知中移除標籤**  
使用 [Unregister-EC2InstanceEventNotificationAttribute](https://docs.aws.amazon.com/powershell/latest/reference/items/Unregister-EC2InstanceEventNotificationAttribute.html) cmdlet。

```
Unregister-EC2InstanceEventNotificationAttribute `
    -InstanceTagAttribute_InstanceTagKey {{tag_key_3}}
```

------

## 檢視要包含在事件通知中的標籤
<a name="view-tags"></a>

可檢視要包含在事件通知中的標籤。

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

**檢視要包含在事件通知中的標籤**

1. 在 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格中，選擇 **Events** (事件)。

1. 選擇 **Actions (動作)**、**Manage event notifications (管理事件通知)**。

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

**若要檢視要包含在事件通知中的標籤**  
使用 [describe-instance-event-notification-attributes](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instance-event-notification-attributes.html) 命令。

```
aws ec2 describe-instance-event-notification-attributes
```

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

**若要檢視要包含在事件通知中的標籤**  
使用 [Get-EC2InstanceEventNotificationAttribute](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2InstanceEventNotificationAttribute.html) cmdlet。

```
Get-EC2InstanceEventNotificationAttribute
```

------