Want to learn more about how to set up an AWS ECR login token with Java? Check out this post to learn more about using the ECR registry in Rancher.
Today, I am going to describe how to get AWS ECR login token with Java. I used this token for the ECR registry in Rancher.
When you want to get the ECR login token with Java and the AWS SDK, then you can achieve this through the following steps.
In order to use Amazon web services, the AWSCredential needs to be supplied in AWS SDK. It can be done by following way.
Now, you will need to fetch the authorization data from the list and then get the encoded token from authorization data. NOTE: Token will be encoded with base64.
This token is encoded with a base64 format. So, it is necessary to decode it into a plain string by the following code.
Now, this token can be used in the Rancher registry credentials and also for the docker CLI to push and pull images with Amazon ECR.