

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

# 使用 CLI 或 API 管理標籤
<a name="tag-resources-api-sdk"></a>

使用下列 AWS CLI 命令或 AWS Batch API 操作來新增、更新、列出和刪除 資源的標籤。


**資源的標籤支援 AWS Batch**  

| 任務 | API 動作 | AWS CLI | AWS Tools for Windows PowerShell | 
| --- | --- | --- | --- | 
| 新增或覆寫一或多個標籤。 | [TagResource](https://docs.aws.amazon.com/batch/latest/APIReference/API_TagResource.html) | [tag-resource](https://docs.aws.amazon.com/cli/latest/reference/batch/tag-resource.html) | [Add-BATResourceTag](https://docs.aws.amazon.com/powershell/latest/reference/items/Add-BATResourceTag.html) | 
| 刪除一或多個標籤。 | [UntagResource](https://docs.aws.amazon.com/batch/latest/APIReference/API_UntagResource.html) | [untag-resource](https://docs.aws.amazon.com/cli/latest/reference/batch/untag-resource.html) | [Remove-BATResourceTag](https://docs.aws.amazon.com/powershell/latest/reference/items/Remove-BATResourceTag.html) | 
| 列出資源的標籤 | [ListTagsForResource](https://docs.aws.amazon.com/batch/latest/APIReference/API_ListTagsForResource.html) | [list-tags-for-resource](https://docs.aws.amazon.com/cli/latest/reference/batch/list-tags-for-resource.html) | [Get-BATResourceTag](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-BATResourceTag.html) | 

下列範例示範如何使用 AWS CLI來標記或取消標記資源。

**範例 1：標記現有資源**  
以下命令會標記現有的資源。

```
aws batch tag-resource --resource-arn {{resource_ARN}} --tags {{team}}={{devs}}
```

**範例 2：取消標記現有的資源**  
以下命令會從現有的資源刪除標籤。

```
aws batch untag-resource --resource-arn {{resource_ARN}} --tag-keys {{tag_key}}
```

**範例 3：列出資源的標籤**  
以下命令列出與現有資源相關聯的標籤。

```
aws batch list-tags-for-resource --resource-arn {{resource_ARN}}
```

有些資源建立動作可讓您在建立資源時指定標籤。下列動作支援在建立時新增標籤。


| 任務 | API 動作 | AWS CLI | AWS Tools for Windows PowerShell | 
| --- | --- | --- | --- | 
| 建立運算環境 | [CreateComputeEnvironment](https://docs.aws.amazon.com/batch/latest/APIReference/API_CreateComputeEnvironment.html) | [create-compute-environment](https://docs.aws.amazon.com/cli/latest/reference/batch/create-compute-environment.html) | [New-BATComputeEnvironment](https://docs.aws.amazon.com/powershell/latest/reference/items/New-BATComputeEnvironment.html) | 
| 建立任務佇列 | [CreateJobQueue](https://docs.aws.amazon.com/batch/latest/APIReference/API_CreateJobQueue.html) | [create-job-queue](https://docs.aws.amazon.com/cli/latest/reference/batch/create-job-queue.html) | [New-BATJobQueue](https://docs.aws.amazon.com/powershell/latest/reference/items/New-BATJobQueue.html) | 
| 建立排程政策 | [CreateSchedulingPolicy](https://docs.aws.amazon.com/batch/latest/APIReference/API_CreateSchedulingPolicy.html) | [create-scheduling-policy](https://docs.aws.amazon.com/cli/latest/reference/batch/create-scheduling-policy.html) | [New-BATSchedulingPolicy](https://docs.aws.amazon.com/powershell/latest/reference/items/New-BATSchedulingPolicy.html) | 
| 註冊任務定義 | [RegisterJobDefinition](https://docs.aws.amazon.com/batch/latest/APIReference/API_RegisterJobDefinition.html) | [register-job-definition](https://docs.aws.amazon.com/cli/latest/reference/batch/register-job-definition.html) | [Register-BATJobDefinition](https://docs.aws.amazon.com/powershell/latest/reference/items/Register-BATJobDefinition.html) | 
| 提交工作 | [SubmitJob](https://docs.aws.amazon.com/batch/latest/APIReference/API_SubmitJob.html) | [submit-job](https://docs.aws.amazon.com/cli/latest/reference/batch/submit-job.html) | [Submit-BATJob](https://docs.aws.amazon.com/powershell/latest/reference/items/Submit-BATJob.html) | 
| 建立消耗性資源 | [CreateConsumableResource](https://docs.aws.amazon.com/batch/latest/APIReference/API_CreateConsumableResource.html) | [create-consumable-resource](https://docs.aws.amazon.com/cli/latest/reference/batch/create-consumable-resource.html) | [Create-BATConsumableResource](https://docs.aws.amazon.com/powershell/latest/reference/items/Create-BATConsumableResource.html) | 