

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

# 標記 資源
<a name="tagging"></a>

標籤是一個自訂中繼資料標籤，您可將其新增至資源，以輕鬆識別、組織和搜尋資源。標籤由兩個單獨的部分組成：標籤金鑰和標籤值。這被稱為一個 key:value 對。

標籤金鑰通常表示較大的分類，而標籤值則表示該分類的子集。例如，您可以有*標籤金鑰 = 顏色*和*標籤值 = 藍色*，這將產生 key:value 對 `Color:Blue`。您可以將標籤的值設為空字串，但您無法將標籤的值設為 Null。忽略標籤值基本上等同於使用空字串。

**提示**  
AWS 帳單與成本管理 可以使用標籤將您的帳單分隔為動態類別。例如，如果您新增標籤以代表公司內的不同部門，例如 `Department:Sales` 或 `Department:Legal`、 AWS 可以提供每個部門的成本分配。

在 中 Amazon Transcribe，您可以標記下列資源：
+ 轉錄作業
+ 醫學轉錄作業
+ 通話分析通話後轉錄任務
+ 自訂詞彙
+ 醫療自訂詞彙
+ 自訂詞彙篩選
+ 呼叫分析類別
+ 自訂語言模型

標籤索引鍵的長度上限為 128 個字元，標籤值的長度上限為 256 個字元；兩者都區分大小寫。每個資源最多 Amazon Transcribe 支援 50 個標籤。對於特定資源，每個標籤金鑰必須是唯一的，且只有一個值。請注意，您的標籤不能以 開頭，`aws:`因為 AWS 會保留此字首給系統產生的標籤。您無法新增、修改或刪除 `aws:*` 標籤，而且它們不計入每個資源的標籤數限制。

**特定資源標籤的 API 操作**  
 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_ListTagsForResource.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_ListTagsForResource.html), [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_TagResource.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_TagResource.html), [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_UntagResource.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_UntagResource.html)   
若要使用標籤 API，您必須在請求中包含 Amazon Resource Name (ARN)。ARN 具有格式 `arn:partition:service:region:account-id:resource-type/resource-id`。例如，與轉錄作業相關的 ARN 可能如下所示：`arn:{{aws}}:transcribe:{{us-west-2}}:{{111122223333}}:transcription-job/{{my-transcription-job-name}}`。

若要進一步了解標記，包括最佳實務，請參閱[標記 AWS 資源](https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html)。

## 標籤式存取控制
<a name="tagging-access-control"></a>

您可以使用標籤來控制 中的存取 AWS 帳戶。對於標籤型存取控制，您可以在 IAM 政策的條件元素中提供標籤資訊。然後您可以使用標籤及其關聯的標籤條件金鑰，以控制下列項目的存取權限：
+ **資源：**根據您指派給這些 Amazon Transcribe 資源的標籤，控制對資源的存取。
  + 使用 `aws:ResourceTag/{{key-name}}` 條件金鑰，以指定必須連接到該資源的 key:value 對。
+ **請求：**控制您可以在請求傳遞的標籤。
  + 使用 `aws:RequestTag/{{key-name}}` 條件索引鍵指定可從 IAM 使用者或角色新增、修改或移除哪些標籤。
+ **授權流程：**控制授權流程的任何部分，控制標籤型的存取。
  +  使用 `aws:TagKeys/` 條件金鑰，以控制是否可在資源或在請求中油主體使用特定標籤金鑰。在此情況下，此鍵值無關緊要。

如需標籤型存取控制政策的範例，請參閱 [根據標籤檢視轉錄作業](security_iam_id-based-policy-examples.md#tagging-transcription-policy)。

如需標籤型存取控制的詳細資訊，請參閱[使用標籤控制 AWS 資源的存取](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html)。

## 將標籤新增至 Amazon Transcribe 資源
<a name="tagging-how-to"></a>

您可以在執行 Amazon Transcribe 任務之前或之後新增標籤。使用現有的 **Create\*** 和 **Start\*** API，您可以在轉錄要求中新增標籤。

您可以使用 **AWS 管理主控台**、或 **AWS CLI** 或 **AWS SDK**，新增、修改或刪除標籤；請參閱下列項目，取得範例：

### AWS 管理主控台
<a name="tagging-console"></a>

1. 登入 [AWS 管理主控台](https://console.aws.amazon.com/transcribe/)。

1. 在導覽窗格中，選擇**轉錄作業**，然後選擇**建立作業**(右上角)。這會開啟**指定作業詳細資訊‭**頁面。

1. 捲動至**指定作業詳細資訊‭**頁面底部，找到**標籤 - *選擇性***方塊，然後選擇**新增標籤**。  
![Amazon Transcribe 主控台螢幕擷取畫面：「指定任務詳細資訊」頁面。](http://docs.aws.amazon.com/zh_tw/transcribe/latest/dg/images/add-new-tag.png)

1. 輸入**金鑰**欄位的資訊，並選擇性輸入**值**欄位。  
![Amazon Transcribe 主控台螢幕擷取畫面：「標籤」面板，顯示範例標籤。](http://docs.aws.amazon.com/zh_tw/transcribe/latest/dg/images/add-new-tag-color.png)

1. 填入您要包含在**指定作業詳細資訊‭**頁面上的任何其他欄位，然後選擇**下一步**。這會引導您前往**設定工作 - *選擇性*頁面**。

   選擇**建立作業**以執行轉錄作業。

1. 您可以導覽至**轉錄作業**頁面、選擇轉錄作業並捲動至工作資訊頁面的底部，檢視與轉錄作業相關的標籤。如果您想要編輯標籤，可以透過選擇**管理標籤**以編輯標籤。  
![Amazon Transcribe 主控台螢幕擷取畫面：轉錄任務資訊頁面中的「標籤」面板。](http://docs.aws.amazon.com/zh_tw/transcribe/latest/dg/images/view-tags.png)

### AWS CLI
<a name="tagging-cli"></a>

此範例使用 [start-transcription-job](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/transcribe/start-transcription-job.html) 指令和 `Tags` 參數。如需詳細資訊，請參閱 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartTranscriptionJob.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartTranscriptionJob.html) 和 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_Tag.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_Tag.html)。

```
aws transcribe start-transcription-job \
--region {{us-west-2}} \
--transcription-job-name {{my-first-transcription-job}} \
--media MediaFileUri=s3://{{amzn-s3-demo-bucket}}/{{my-input-files}}/{{my-media-file}}.{{flac}} \
--output-bucket-name {{amzn-s3-demo-bucket}} \
--output-key {{my-output-files}}/ \
--language-code {{en-US}} \
--tags Key={{color}},Value={{blue}} Key={{shape}},Value={{square}}
```

這是使用 [start-transcription-job](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/transcribe/start-transcription-job.html) 指令的另一個範例，以及新增標籤到工作的請求內文。

```
aws transcribe start-transcription-job \
--region {{us-west-2}} \
--cli-input-json file://{{filepath}}/{{my-first-tagging-job.json}}
```

檔案 *my-first-tagging-job.json* 包含以下請求內文。

```
{
  "TranscriptionJobName": "{{my-first-transcription-job}}",
  "Media": {
        "MediaFileUri": "s3://{{amzn-s3-demo-bucket}}/{{my-input-files}}/{{my-media-file}}.{{flac}}"
  },
  "OutputBucketName": "{{amzn-s3-demo-bucket}}",
  "OutputKey": "{{my-output-files}}/", 
  "LanguageCode": "{{en-US}}",
  "Tags": [ 
        {
           "Key": "{{color}}",
           "Value": "{{blue}}"
        },
        {
           "Key": "{{shape}}",
           "Value": "{{square}}"
        }
  ]
}
```

### 適用於 Python (Boto3) 的 AWS SDK
<a name="tagging-python-batch"></a>

下列範例使用 適用於 Python (Boto3) 的 AWS SDK 來新增標籤，方法是使用 [start\_transcription\_job](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/transcribe.html#TranscribeService.Client.start_transcription_job) 方法的 `Tags` 引數。如需詳細資訊，請參閱 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartTranscriptionJob.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartTranscriptionJob.html) 和 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_Tag.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_Tag.html)。

如需使用 AWS SDKs 的其他範例，包括功能特定、案例和跨服務範例，請參閱 [Amazon Transcribe AWS SDKs的程式碼範例](service_code_examples.md)章節。

```
from __future__ import print_function
import time
import boto3
transcribe = boto3.client('transcribe', '{{us-west-2}}')
job_name = "{{my-first-transcription-job}}"
job_uri = "s3://{{amzn-s3-demo-bucket}}/{{my-input-files}}/{{my-media-file}}.{{flac}}"
transcribe.start_transcription_job(
    TranscriptionJobName = job_name,
    Media = {
        'MediaFileUri': job_uri
    },
    OutputBucketName = '{{amzn-s3-demo-bucket}}',
    OutputKey = '{{my-output-files}}/', 
    LanguageCode = '{{en-US}}', 
    Tags = [
        {
            'Key':'{{color}}', 
            'Value':'{{blue}}'
        }
    ]
)

while True:
    status = transcribe.get_transcription_job(TranscriptionJobName = job_name)
    if status['TranscriptionJob']['TranscriptionJobStatus'] in ['COMPLETED', 'FAILED']:
        break
    print("Not ready yet...")
    time.sleep(5)
print(status)
```