AWS SDK または CLI DeleteRepositoryで を使用する - AWS SDK コードの例

Doc AWS SDK Examples リポジトリには、他にも SDK の例があります。 AWS GitHub

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK または CLI DeleteRepositoryで を使用する

以下のコード例は、DeleteRepository の使用方法を示しています。

アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。

CLI
AWS CLI

リポジトリを削除するには

次のコマンドdelete-repository例では、 アカウントのデフォルトレジストリ内の指定されたリポジトリを強制的に削除します。リポジトリにイメージが含まれている場合は、 --forceフラグが必要です。

aws ecr delete-repository \ --repository-name ubuntu \ --force

出力:

{ "repository": { "registryId": "123456789012", "repositoryName": "ubuntu", "repositoryArn": "arn:aws:ecr:us-west-2:123456789012:repository/ubuntu" } }

詳細については、「Amazon ECR ユーザーガイド」の「リポジトリの削除」を参照してください。

  • API の詳細については、「 コマンドリファレンスDeleteRepository」の「」を参照してください。 AWS CLI

Java
SDK for Java 2.x
注記

については、「」を参照してください GitHub。AWS コード例リポジトリ で全く同じ例を見つけて、設定と実行の方法を確認してください。

/** * Deletes an ECR (Elastic Container Registry) repository. * * @param repoName the name of the repository to delete. * @throws IllegalArgumentException if the repository name is null or empty. * @throws EcrException if there is an error deleting the repository. * @throws RuntimeException if an unexpected error occurs during the deletion process. */ public void deleteECRRepository(String repoName) { if (repoName == null || repoName.isEmpty()) { throw new IllegalArgumentException("Repository name cannot be null or empty"); } DeleteRepositoryRequest repositoryRequest = DeleteRepositoryRequest.builder() .force(true) .repositoryName(repoName) .build(); CompletableFuture<DeleteRepositoryResponse> response = getAsyncClient().deleteRepository(repositoryRequest); response.whenComplete((deleteRepositoryResponse, ex) -> { if (deleteRepositoryResponse != null) { System.out.println("You have successfully deleted the " + repoName + " repository"); } else { Throwable cause = ex.getCause(); if (cause instanceof EcrException) { throw (EcrException) cause; } else { throw new RuntimeException("Unexpected error: " + cause.getMessage(), cause); } } }); // Wait for the CompletableFuture to complete response.join(); }
  • API の詳細については、「 API リファレンスDeleteRepository」の「」を参照してください。 AWS SDK for Java 2.x

Kotlin
SDK for Kotlin
注記

については、「」を参照してください GitHub。AWS コード例リポジトリ で全く同じ例を見つけて、設定と実行の方法を確認してください。

/** * Deletes an ECR (Elastic Container Registry) repository. * * @param repoName the name of the repository to delete. */ suspend fun deleteECRRepository(repoName: String) { if (repoName.isNullOrEmpty()) { throw IllegalArgumentException("Repository name cannot be null or empty") } val repositoryRequest = DeleteRepositoryRequest { force = true repositoryName = repoName } EcrClient { region = "us-east-1" }.use { ecrClient -> ecrClient.deleteRepository(repositoryRequest) println("You have successfully deleted the $repoName repository") } }
  • API の詳細については、 AWS SDK for Kotlin API リファレンスDeleteRepositoryの「」を参照してください。