本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
致電 Amazon Lookout for Vision 操作
運行以下代碼以確認您可以撥打電話到 Amazon Lookout for Vision API。該代碼列出了您的項目 AWS 帳戶,在目前 AWS 區域。如果您之前尚未建立專案,則回應為空白,但確認您可以呼叫該 ListProjects
操作。
通常,調用示例函數需要 AWS SDK Lookout for Vision 客戶端和任何其他必需的參數。Lo AWS SDK okout for Vision 客戶端在主要功能中聲明。
如果程式碼失敗,請檢查您使用的使用者是否擁有正確的權限。還要檢查 AWS 您用作 Amazon Lookout for Vision 區域並非所有區域都可用 AWS 區域。
致電 Amazon Lookout for Vision 操作
-
如果您尚未這樣做,請安裝並配置 AWS CLI 和 AWS SDKs。如需詳細資訊,請參閱步驟 4:設定 AWS CLI 以及 AWS SDKs。
-
使用以下的範例程式碼來檢視您的專案。
- CLI
-
使用
list-projects
指令列出您帳戶中的專案。aws lookoutvision list-projects \ --profile lookoutvision-access
- Python
-
此代碼取自 AWS 文檔SDK示例 GitHub 存儲庫。請參閱此處
的完整範例。 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 from botocore.exceptions import ClientError import boto3 class GettingStarted: @staticmethod def list_projects(lookoutvision_client): """ Lists information about the projects that are in in your AWS account and in the current AWS Region. :param lookoutvision_client: A Boto3 Lookout for Vision client. """ try: response = lookoutvision_client.list_projects() for project in response["Projects"]: print("Project: " + project["ProjectName"]) print("ARN: " + project["ProjectArn"]) print() print("Done!") except ClientError: raise def main(): session = boto3.Session(profile_name='lookoutvision-access') lookoutvision_client = session.client("lookoutvision") GettingStarted.list_projects(lookoutvision_client) if __name__ == "__main__": main()
- Java V2
-
此代碼取自 AWS 文檔SDK示例 GitHub 存儲庫。請參閱此處
的完整範例。 /* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ package com.example.lookoutvision; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.services.lookoutvision.LookoutVisionClient; import software.amazon.awssdk.services.lookoutvision.model.ProjectMetadata; import software.amazon.awssdk.services.lookoutvision.paginators.ListProjectsIterable; import software.amazon.awssdk.services.lookoutvision.model.ListProjectsRequest; import software.amazon.awssdk.services.lookoutvision.model.LookoutVisionException; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; public class GettingStarted { public static final Logger logger = Logger.getLogger(GettingStarted.class.getName()); /** * Lists the Amazon Lookoutfor Vision projects in the current AWS account and * AWS Region. * * @param lfvClient An Amazon Lookout for Vision client. * @return List<ProjectMetadata> Metadata for each project. */ public static List<ProjectMetadata> listProjects(LookoutVisionClient lfvClient) throws LookoutVisionException { logger.log(Level.INFO, "Getting projects:"); ListProjectsRequest listProjectsRequest = ListProjectsRequest.builder() .maxResults(100) .build(); List<ProjectMetadata> projectMetadata = new ArrayList<>(); ListProjectsIterable projects = lfvClient.listProjectsPaginator(listProjectsRequest); projects.stream().flatMap(r -> r.projects().stream()) .forEach(project -> { projectMetadata.add(project); logger.log(Level.INFO, project.projectName()); }); logger.log(Level.INFO, "Finished getting projects."); return projectMetadata; } public static void main(String[] args) throws Exception { try { // Get the Lookout for Vision client. LookoutVisionClient lfvClient = LookoutVisionClient.builder() .credentialsProvider(ProfileCredentialsProvider.create("lookoutvision-access")) .build(); List<ProjectMetadata> projects = Projects.listProjects(lfvClient); System.out.printf("Projects%n--------%n"); for (ProjectMetadata project : projects) { System.out.printf("Name: %s%n", project.projectName()); System.out.printf("ARN: %s%n", project.projectArn()); System.out.printf("Date: %s%n%n", project.creationTimestamp().toString()); } } catch (LookoutVisionException lfvError) { logger.log(Level.SEVERE, "Could not list projects: {0}: {1}", new Object[] { lfvError.awsErrorDetails().errorCode(), lfvError.awsErrorDetails().errorMessage() }); System.out.println(String.format("Could not list projects: %s", lfvError.getMessage())); System.exit(1); } } }
設定SDK權限
步驟 5:(可選)使用您自己的 AWS KMS 金錀