从ECR存储库使用AWS SDK拉取最新的镜像标签。

huangapple go评论95阅读模式
英文:

pull the latest image tag from ECR repo using AWS SDK

问题

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 = ListTagsForResource(request);
    			   	
    	System.out.println(r.getTags());   
    }
}

在这段代码中,你需要将 request.setResourceArn("arn:aws:ecr:us-east-1:45454512:repository/testrty"); 修改为 request.setResourceArn("arn:aws:ecr:us-east-1:45454512:repository/testrty");

英文:

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

答案1

得分: 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 you'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());
    }
}
英文:

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());
    }
}

huangapple
  • 本文由 发表于 2023年6月12日 00:17:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76451381.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定