

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 列出资源的标签
<a name="list-tag-resource"></a>

使用[https://docs.aws.amazon.com/healthimaging/latest/APIReference/API_ListTagsForResource.html](https://docs.aws.amazon.com/healthimaging/latest/APIReference/API_ListTagsForResource.html)操作列出 AWS 中[数据存储](getting-started-concepts.md#concept-data-store)和[图像集](getting-started-concepts.md#concept-image-set)的标签 HealthImaging。以下代码示例描述了如何将`ListTagsForResource`操作与 AWS 管理控制台 AWS CLI、和一起使用 AWS SDKs。有关更多信息，请参阅*AWS 一般参考 指南*中的为[AWS 资源添加标签](https://docs.aws.amazon.com/tag-editor/latest/userguide/tagging.html)。

**列出资源标签**  
根据您对 AWS 的访问偏好选择菜单 HealthImaging。

## AWS 控制台
<a name="code-example-console-list-tag-resource"></a>

1. 打开 HealthImaging 控制台[数据存储页面](https://console.aws.amazon.com/medical-imaging/home#/dataStores)。

1. 选择数据存储。

   **数据存储详细信息**页面将会打开。

1. 选择**详细信息**选项卡。

   在**标签**部分下，列出了所有数据存储标签。

## AWS CLI 和 SDKs
<a name="code-example-cli-sdk-list-tag-resource"></a>

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

**AWS CLI**  
**示例 1：列出数据存储的资源标签**  
以下 `list-tags-for-resource` 代码示例列出数据存储的标签。  

```
aws medical-imaging list-tags-for-resource \
    --resource-arn "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012"
```
输出：  

```
{
    "tags":{
        "Deployment":"Development"
    }
}
```
**例 2：列出图像集的资源标签**  
以下 `list-tags-for-resource` 代码示例列出图像集的标签。  

```
aws medical-imaging list-tags-for-resource \
    --resource-arn "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012/imageset/18f88ac7870584f58d56256646b4d92b"
```
输出：  

```
{
    "tags":{
        "Deployment":"Development"
    }
}
```
有关更多信息，请参阅《*AWS HealthImaging 开发人员指南》 AWS HealthImaging*中的[使用为资源添加标签](https://docs.aws.amazon.com/healthimaging/latest/devguide/tagging.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/medical-imaging/list-tags-for-resource.html)*中的。

------
#### [ Java ]

**适用于 Java 的 SDK 2.x**  

```
    public static ListTagsForResourceResponse listMedicalImagingResourceTags(MedicalImagingClient medicalImagingClient,
            String resourceArn) {
        try {
            ListTagsForResourceRequest listTagsForResourceRequest = ListTagsForResourceRequest.builder()
                    .resourceArn(resourceArn)
                    .build();

            return medicalImagingClient.listTagsForResource(listTagsForResourceRequest);
        } catch (MedicalImagingException e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }

        return null;
    }
```
+  有关 API 的详细信息，请参阅 *AWS SDK for Java 2.x API 参考[ListTagsForResource](https://docs.aws.amazon.com/goto/SdkForJavaV2/medical-imaging-2023-07-19/ListTagsForResource)*中的。
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/medicalimaging#code-examples)中查找完整示例，了解如何进行设置和运行。

------
#### [ JavaScript ]

**适用于 JavaScript (v3) 的软件开发工具包**  

```
import { ListTagsForResourceCommand } from "@aws-sdk/client-medical-imaging";
import { medicalImagingClient } from "../libs/medicalImagingClient.js";

/**
 * @param {string} resourceArn - The Amazon Resource Name (ARN) for the data store or image set.
 */
export const listTagsForResource = async (
  resourceArn = "arn:aws:medical-imaging:us-east-1:abc:datastore/def/imageset/ghi",
) => {
  const response = await medicalImagingClient.send(
    new ListTagsForResourceCommand({ resourceArn: resourceArn }),
  );
  console.log(response);
  // {
  //     '$metadata': {
  //         httpStatusCode: 200,
  //         requestId: '008fc6d3-abec-4870-a155-20fa3631e645',
  //         extendedRequestId: undefined,
  //         cfId: undefined,
  //         attempts: 1,
  //         totalRetryDelay: 0
  //     },
  //     tags: { Deployment: 'Development' }
  // }

  return response;
};
```
+  有关 API 的详细信息，请参阅 *适用于 JavaScript 的 AWS SDK API 参考[ListTagsForResource](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/medical-imaging/command/ListTagsForResourceCommand)*中的。
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javascriptv3/example_code/medical-imaging#code-examples)中查找完整示例，了解如何进行设置和运行。

------
#### [ Python ]

**适用于 Python 的 SDK（Boto3）**  

```
class MedicalImagingWrapper:
    def __init__(self, health_imaging_client):
        self.health_imaging_client = health_imaging_client


    def list_tags_for_resource(self, resource_arn):
        """
        List the tags for a resource.

        :param resource_arn: The ARN of the resource.
        :return: The list of tags.
        """
        try:
            tags = self.health_imaging_client.list_tags_for_resource(
                resourceArn=resource_arn
            )
        except ClientError as err:
            logger.error(
                "Couldn't list tags for resource. Here's why: %s: %s",
                err.response["Error"]["Code"],
                err.response["Error"]["Message"],
            )
            raise
        else:
            return tags["tags"]
```
以下代码实例化对象。 MedicalImagingWrapper   

```
    client = boto3.client("medical-imaging")
    medical_imaging_wrapper = MedicalImagingWrapper(client)
```
+  有关 API 的详细信息，请参阅适用[ListTagsForResource](https://docs.aws.amazon.com/goto/boto3/medical-imaging-2023-07-19/ListTagsForResource)于 *Python 的AWS SDK (Boto3) API 参考*。
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/medical-imaging#code-examples)中查找完整示例，了解如何进行设置和运行。

------
#### [ SAP ABAP ]

**适用于 SAP ABAP 的 SDK**  

```
    TRY.
        " iv_resource_arn = 'arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012'
        oo_result = lo_mig->listtagsforresource( iv_resourcearn = iv_resource_arn ).
        DATA(lt_tags) = oo_result->get_tags( ).
        DATA(lv_count) = lines( lt_tags ).
        MESSAGE |Found { lv_count } tags for resource.| TYPE 'I'.
      CATCH /aws1/cx_migaccessdeniedex.
        MESSAGE 'Access denied.' TYPE 'I'.
      CATCH /aws1/cx_miginternalserverex.
        MESSAGE 'Internal server error.' TYPE 'I'.
      CATCH /aws1/cx_migresourcenotfoundex.
        MESSAGE 'Resource not found.' TYPE 'I'.
      CATCH /aws1/cx_migthrottlingex.
        MESSAGE 'Request throttled.' TYPE 'I'.
      CATCH /aws1/cx_migvalidationex.
        MESSAGE 'Validation error.' TYPE 'I'.
    ENDTRY.
```
+  有关 API 的详细信息，请参阅适用[ListTagsForResource](https://docs.aws.amazon.com/sdk-for-sap-abap/v1/api/latest/index.html)于 S *AP 的AWS SDK ABAP API 参考*。
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/sap-abap/services/mig#code-examples)中查找完整示例，了解如何进行设置和运行。

------

**示例可用性**  
找不到所需的内容？ 使用本页右侧边栏上的 “**提供反馈**” 链接请求代码示例。