Gunakan DeleteRepository dengan AWS SDK atau CLI - AWS Contoh Kode SDK

Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh SDK AWS Doc. GitHub

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan DeleteRepository dengan AWS SDK atau CLI

Contoh kode berikut menunjukkan cara menggunakanDeleteRepository.

Contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Anda dapat melihat tindakan ini dalam konteks dalam contoh kode berikut:

CLI
AWS CLI

Untuk menghapus repositori

delete-repositoryContoh perintah force berikut menghapus repositori yang ditentukan dalam registri default untuk akun. --forceBendera diperlukan jika repositori berisi gambar.

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

Output:

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

Untuk informasi selengkapnya, lihat Menghapus Repositori di Panduan Pengguna Amazon ECR.

Java
SDK untuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di AWS Repositori Contoh Kode.

/** * 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(); }
  • Untuk detail API, lihat DeleteRepositorydi Referensi AWS SDK for Java 2.x API.

Kotlin
SDK untuk Kotlin
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di AWS Repositori Contoh Kode.

/** * 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") } }
  • Untuk detail API, lihat DeleteRepositorydi AWS SDK untuk referensi API Kotlin.