本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
DescribeRepositories
搭配 AWS SDK或 使用 CLI
下列程式碼範例示範如何使用 DescribeRepositories
。
動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:
- CLI
-
- AWS CLI
-
描述登錄檔中的儲存庫
此範例說明 帳戶預設登錄檔中的儲存庫。
命令:
aws ecr describe-repositories
輸出:
{ "repositories": [ { "registryId": "012345678910", "repositoryName": "ubuntu", "repositoryArn": "arn:aws:ecr:us-west-2:012345678910:repository/ubuntu" }, { "registryId": "012345678910", "repositoryName": "test", "repositoryArn": "arn:aws:ecr:us-west-2:012345678910:repository/test" } ] }
-
如需API詳細資訊,請參閱 AWS CLI 命令參考DescribeRepositories
中的 。
-
- Java
-
- SDK 適用於 Java 2.x
-
注意
還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 /** * Retrieves the repository URI for the specified repository name. * * @param repoName the name of the repository to retrieve the URI for. * @return the repository URI for the specified repository name. * @throws EcrException if there is an error retrieving the repository information. * @throws CompletionException if the asynchronous operation completes exceptionally. */ public void getRepositoryURI(String repoName) { DescribeRepositoriesRequest request = DescribeRepositoriesRequest.builder() .repositoryNames(repoName) .build(); CompletableFuture<DescribeRepositoriesResponse> response = getAsyncClient().describeRepositories(request); response.whenComplete((describeRepositoriesResponse, ex) -> { if (ex != null) { Throwable cause = ex.getCause(); if (cause instanceof InterruptedException) { Thread.currentThread().interrupt(); String errorMessage = "Thread interrupted while waiting for asynchronous operation: " + cause.getMessage(); throw new RuntimeException(errorMessage, cause); } else if (cause instanceof EcrException) { throw (EcrException) cause; } else { String errorMessage = "Unexpected error: " + cause.getMessage(); throw new RuntimeException(errorMessage, cause); } } else { if (describeRepositoriesResponse != null) { if (!describeRepositoriesResponse.repositories().isEmpty()) { String repositoryUri = describeRepositoriesResponse.repositories().get(0).repositoryUri(); System.out.println("Repository URI found: " + repositoryUri); } else { System.out.println("No repositories found for the given name."); } } else { System.err.println("No response received from describeRepositories."); } } }); response.join(); }
-
如需API詳細資訊,請參閱 AWS SDK for Java 2.x API 參考DescribeRepositories中的 。
-
- Kotlin
-
- SDK 適用於 Kotlin
-
注意
還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 /** * Retrieves the repository URI for the specified repository name. * * @param repoName the name of the repository to retrieve the URI for. * @return the repository URI for the specified repository name. */ suspend fun getRepositoryURI(repoName: String?): String? { require(!(repoName == null || repoName.isEmpty())) { "Repository name cannot be null or empty" } val request = DescribeRepositoriesRequest { repositoryNames = listOf(repoName) } EcrClient { region = "us-east-1" }.use { ecrClient -> val describeRepositoriesResponse = ecrClient.describeRepositories(request) if (!describeRepositoriesResponse.repositories?.isEmpty()!!) { return describeRepositoriesResponse?.repositories?.get(0)?.repositoryUri } else { println("No repositories found for the given name.") return "" } } }
-
如需API詳細資訊,請參閱 DescribeRepositories
中的 AWS SDK Kotlin API參考。
-
- Rust
-
- SDK for Rust
-
注意
還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 async fn show_repos(client: &aws_sdk_ecr::Client) -> Result<(), aws_sdk_ecr::Error> { let rsp = client.describe_repositories().send().await?; let repos = rsp.repositories(); println!("Found {} repositories:", repos.len()); for repo in repos { println!(" ARN: {}", repo.repository_arn().unwrap()); println!(" Name: {}", repo.repository_name().unwrap()); } Ok(()) }
-
如需API詳細資訊,請參閱 DescribeRepositories
中的 AWS SDK for Rust API參考。
-
如需開發人員指南和程式碼範例的完整清單 AWS SDK,請參閱 ECR 搭配 使用 Amazon AWS SDK。本主題也包含入門的相關資訊,以及先前SDK版本的詳細資訊。
DescribeImages
GetAuthorizationToken