搭ListDatastores配使用 AWS SDK或 CLI - AWS HealthImaging

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

ListDatastores配使用 AWS SDK或 CLI

下列程式碼範例會示範如何使用ListDatastores

Bash
AWS CLI 與 Bash 腳本
############################################################################### # function errecho # # This function outputs everything sent to it to STDERR (standard error output). ############################################################################### function errecho() { printf "%s\n" "$*" 1>&2 } ############################################################################### # function imaging_list_datastores # # List the HealthImaging data stores in the account. # # Returns: # [[datastore_name, datastore_id, datastore_status]] # And: # 0 - If successful. # 1 - If it fails. ############################################################################### function imaging_list_datastores() { local option OPTARG # Required to use getopts command in a function. local error_code # bashsupport disable=BP5008 function usage() { echo "function imaging_list_datastores" echo "Lists the AWS HealthImaging data stores in the account." echo "" } # Retrieve the calling parameters. while getopts "h" option; do case "${option}" in h) usage return 0 ;; \?) echo "Invalid parameter" usage return 1 ;; esac done export OPTIND=1 local response response=$(aws medical-imaging list-datastores \ --output text \ --query "datastoreSummaries[*][datastoreName, datastoreId, datastoreStatus]") error_code=${?} if [[ $error_code -ne 0 ]]; then aws_cli_error_log $error_code errecho "ERROR: AWS reports list-datastores operation failed.$response" return 1 fi echo "$response" return 0 }
  • 有API關詳細資訊,請參閱 ListDatastoresAWS CLI 指令參考

注意

還有更多關於 GitHub。尋找完整範例,並瞭解如何在 AWS 代碼示例存儲庫

CLI
AWS CLI

列示資料倉庫的步驟

下列list-datastores程式碼範例會列出可用的資料存放區。

aws medical-imaging list-datastores

輸出:

{ "datastoreSummaries": [ { "datastoreId": "12345678901234567890123456789012", "datastoreName": "TestDatastore123", "datastoreStatus": "ACTIVE", "datastoreArn": "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012", "createdAt": "2022-11-15T23:33:09.643000+00:00", "updatedAt": "2022-11-15T23:33:09.643000+00:00" } ] }

如需詳細資訊,請參閱中的列出資料存放區 AWS HealthImaging 開發人員指南

  • 有API關詳細資訊,請參閱 ListDatastoresAWS CLI 指令參考

Java
SDK對於爪哇 2.x
public static List<DatastoreSummary> listMedicalImagingDatastores(MedicalImagingClient medicalImagingClient) { try { ListDatastoresRequest datastoreRequest = ListDatastoresRequest.builder() .build(); ListDatastoresIterable responses = medicalImagingClient.listDatastoresPaginator(datastoreRequest); List<DatastoreSummary> datastoreSummaries = new ArrayList<>(); responses.stream().forEach(response -> datastoreSummaries.addAll(response.datastoreSummaries())); return datastoreSummaries; } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; }
  • 有API關詳細資訊,請參閱 ListDatastoresAWS SDK for Java 2.x API參考

注意

還有更多關於 GitHub。尋找完整範例,並瞭解如何在 AWS 代碼示例存儲庫

JavaScript
SDK對於 JavaScript (3)
import { paginateListDatastores } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; export const listDatastores = async () => { const paginatorConfig = { client: medicalImagingClient, pageSize: 50, }; const commandParams = {}; const paginator = paginateListDatastores(paginatorConfig, commandParams); /** * @type {import("@aws-sdk/client-medical-imaging").DatastoreSummary[]} */ const datastoreSummaries = []; for await (const page of paginator) { // Each page contains a list of `jobSummaries`. The list is truncated if is larger than `pageSize`. datastoreSummaries.push(...page["datastoreSummaries"]); console.log(page); } // { // '$metadata': { // httpStatusCode: 200, // requestId: '6aa99231-d9c2-4716-a46e-edb830116fa3', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // datastoreSummaries: [ // { // createdAt: 2023-08-04T18:49:54.429Z, // datastoreArn: 'arn:aws:medical-imaging:us-east-1:xxxxxxxxx:datastore/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // datastoreId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // datastoreName: 'my_datastore', // datastoreStatus: 'ACTIVE', // updatedAt: 2023-08-04T18:49:54.429Z // } // ... // ] // } return datastoreSummaries; };
  • 有API關詳細資訊,請參閱 ListDatastoresAWS SDK for JavaScript API參考

注意

還有更多關於 GitHub。尋找完整範例,並瞭解如何在 AWS 代碼示例存儲庫

Python
SDK對於 Python(肉毒桿菌 3)
class MedicalImagingWrapper: def __init__(self, health_imaging_client): self.health_imaging_client = health_imaging_client def list_datastores(self): """ List the data stores. :return: The list of data stores. """ try: paginator = self.health_imaging_client.get_paginator("list_datastores") page_iterator = paginator.paginate() datastore_summaries = [] for page in page_iterator: datastore_summaries.extend(page["datastoreSummaries"]) except ClientError as err: logger.error( "Couldn't list data stores. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return datastore_summaries

下面的代碼實例化對 MedicalImagingWrapper 象。

client = boto3.client("medical-imaging") medical_imaging_wrapper = MedicalImagingWrapper(client)
  • 有API關詳細資訊,請參閱 ListDatastoresAWS SDK對於 Python(肉毒桿 3)API參考。

注意

還有更多關於 GitHub。尋找完整範例,並瞭解如何在 AWS 代碼示例存儲庫

有關的完整列表 AWS SDK開發人員指南和代碼示例,請參閱搭 HealthImaging 配 AWS SDK 使用。本主題也包含有關入門的資訊以及舊SDK版的詳細資訊。