0

Im trying to pull the latest image tag from the AWS ECR repo using AWS SDK

Im trying to write below code from the documentation and the google search

public class AwsECRTest {
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ListTagsForResourceRequest request = new ListTagsForResourceRequest();
        request.setResourceArn("arn:aws:ecr:us-east-1:45454512:repository/testrty");
                   
        ListTagsForResourceResult r(ListTagsForResourceRequest request);           
                   
        System.out.println(r.getTags());   
    }
}

getting below error

    Syntax error on token "ListTagsForResourceResult", record expected

not sure , how to pass the request object to ListTagsForResourceResult

please help / suggest

this is the doc link : https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-ecr/src/main/java/com/amazonaws/services/ecr/AmazonECR.java

Yahor Barkouski
  • 1,361
  • 1
  • 5
  • 21
user2315104
  • 2,378
  • 7
  • 35
  • 54
  • 1
    `listTagsForResource` just returns the AWS resource tags for the ECR repository, not the docker image tags for the images stored in the repository. If you look at other AWS services/resources, every one of them have a `listTagsForResource`. You will need to call `listImages` to get the details of the images in the repository, including their tags. – Mark B Jun 13 '23 at 12:20
  • @MarkB: Thank you very much. I will have a look Is there any way to get the Latest Tag ? I'm interested in getting latest image tag for image in repository – user2315104 Jun 13 '23 at 19:20

1 Answers1

1

You're trying to create an object r of type ListTagsForResourceResult and call a method r() simultaneously, unfortunately that's not going to work in Java.

The ListTagsForResourceResult object should be returned from a method call from an instance of the AmazonECR client, so iou'll need to set up an AmazonECR to interact with your ECR repository first, and then call the listTagsForResource() method on the client with your request as an argument:

public class AwsECRTest {

    public static void main(String[] args) {
        
        AmazonECR ecr = AmazonECRClientBuilder.defaultClient();
        
        ListTagsForResourceRequest request = new ListTagsForResourceRequest();
        request.setResourceArn("arn:aws:ecr:us-east-1:45454512:repository/testrty");
        
        ListTagsForResourceResult result = ecr.listTagsForResource(request);
        
        System.out.println(result.getTags());
    }
}
Yahor Barkouski
  • 1,361
  • 1
  • 5
  • 21
  • thanks for the code . however, the list is empty. result.getTags() is coming as empty but I can see the tags on the AWS console – user2315104 Jun 11 '23 at 18:46