Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 AWS
翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
AWS SDK または CLI DescribeImages
で を使用する
以下のコード例は、DescribeImages
の使用方法を示しています。
アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。
- CLI
-
- AWS CLI
-
リポジトリ内のイメージを記述する場合
次の
describe-images
の例では、cluster-autoscaler
リポジトリ内でタグv1.13.6
が付いているイメージに関する詳細を表示します。aws ecr describe-images \ --repository-name
cluster-autoscaler
\ --image-idsimageTag=v1.13.6
出力:
{ "imageDetails": [ { "registryId": "012345678910", "repositoryName": "cluster-autoscaler", "imageDigest": "sha256:4a1c6567c38904384ebc64e35b7eeddd8451110c299e3368d2210066487d97e5", "imageTags": [ "v1.13.6" ], "imageSizeInBytes": 48318255, "imagePushedAt": 1565128275.0 } ] }
-
API の詳細については、「AWS CLI コマンドリファレンス」の「DescribeImages
」を参照してください。
-
- Java
-
- SDK for Java 2.x
-
注記
GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 /** * Verifies the existence of an image in an Amazon Elastic Container Registry (Amazon ECR) repository asynchronously. * * @param repositoryName The name of the Amazon ECR repository. * @param imageTag The tag of the image to verify. * @throws EcrException if there is an error retrieving the image information from Amazon ECR. * @throws CompletionException if the asynchronous operation completes exceptionally. */ public void verifyImage(String repositoryName, String imageTag) { DescribeImagesRequest request = DescribeImagesRequest.builder() .repositoryName(repositoryName) .imageIds(ImageIdentifier.builder().imageTag(imageTag).build()) .build(); CompletableFuture<DescribeImagesResponse> response = getAsyncClient().describeImages(request); response.whenComplete((describeImagesResponse, ex) -> { if (ex != null) { if (ex instanceof CompletionException) { Throwable cause = ex.getCause(); if (cause instanceof EcrException) { throw (EcrException) cause; } else { throw new RuntimeException("Unexpected error: " + cause.getMessage(), cause); } } else { throw new RuntimeException("Unexpected error: " + ex.getCause()); } } else if (describeImagesResponse != null && !describeImagesResponse.imageDetails().isEmpty()) { System.out.println("Image is present in the repository."); } else { System.out.println("Image is not present in the repository."); } }); // Wait for the CompletableFuture to complete. response.join(); }
-
API の詳細については、「AWS SDK for Java 2.x API リファレンス」の「DescribeImages」を参照してください。
-
- Kotlin
-
- SDK for Kotlin
-
注記
GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 /** * Verifies the existence of an image in an Amazon Elastic Container Registry (Amazon ECR) repository asynchronously. * * @param repositoryName The name of the Amazon ECR repository. * @param imageTag The tag of the image to verify. */ suspend fun verifyImage( repoName: String?, imageTagVal: String?, ) { require(!(repoName == null || repoName.isEmpty())) { "Repository name cannot be null or empty" } require(!(imageTagVal == null || imageTagVal.isEmpty())) { "Image tag cannot be null or empty" } val imageId = ImageIdentifier { imageTag = imageTagVal } val request = DescribeImagesRequest { repositoryName = repoName imageIds = listOf(imageId) } EcrClient { region = "us-east-1" }.use { ecrClient -> val describeImagesResponse = ecrClient.describeImages(request) if (describeImagesResponse != null && !describeImagesResponse.imageDetails?.isEmpty()!!) { println("Image is present in the repository.") } else { println("Image is not present in the repository.") } } }
-
API の詳細については、「AWS SDK for Kotlin API リファレンス」の「DescribeImages
」を参照してください。
-
- Python
-
- SDK for Python (Boto3)
-
注記
GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 class ECRWrapper: def __init__(self, ecr_client: client): self.ecr_client = ecr_client @classmethod def from_client(cls) -> "ECRWrapper": """ Creates a ECRWrapper instance with a default Amazon ECR client. :return: An instance of ECRWrapper initialized with the default Amazon ECR client. """ ecr_client = boto3.client("ecr") return cls(ecr_client) def describe_images( self, repository_name: str, image_ids: list[str] = None ) -> list[dict]: """ Describes ECR images. :param repository_name: The name of the repository to describe images for. :param image_ids: The optional IDs of images to describe. :return: The list of image descriptions. """ try: params = { "repositoryName": repository_name, } if image_ids is not None: params["imageIds"] = [{"imageTag": tag} for tag in image_ids] paginator = self.ecr_client.get_paginator("describe_images") image_descriptions = [] for page in paginator.paginate(**params): image_descriptions.extend(page["imageDetails"]) return image_descriptions except ClientError as err: logger.error( "Couldn't describe images. Here's why %s", err.response["Error"]["Message"], ) raise
-
API の詳細については、「AWS SDK for Python (Boto3) API リファレンス」の「DescribeImages」を参照してください。
-