Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS ECR login with JavaScript SDK --no-include-email flag

I'm trying to run this AWS CLI command:

aws ecr get-login --no-include-email --region <my-region>

But using the JavaScript SDK with new AWS.ECR(..).getAuthorizationToken method but I'm getting this error:

Error response from daemon: login attempt to https://xxxxx.dkr.ecr.<my-region>.amazonaws.com/v2/ failed with status: 400 Bad Request

From my understanding, I need to use some flag that is equal to the --no-include-email argument in the CLI command but I cannot find how to set it with the JavaScript SDK.

This is my code:

const ecr = new AWS.ECR({
    apiVersion: '2015-09-21',
    region: 'my-region'
});

const { authorizationData } = await ecr.getAuthorizationToken().promise();

if(!authorizationData || !authorizationData[0] || !authorizationData[0].authorizationToken){
    throw new Error('AWS getAuthorizationToken failed');
}

const password = authorizationData[0].authorizationToken;
const proxyEndpoint = authorizationData[0].proxyEndpoint;

await childProcessP.spawn('docker', [
    'login',
    '-u', 'AWS',
    '-p', password,
    proxyEndpoint
]);

Do anyone know how to do it?

like image 459
Shlomi Avatar asked Aug 05 '26 23:08

Shlomi


1 Answers

the AuthorizationToken contains a base64 encoded <username>:<password>

all you need to do is decode and split to get the values you want.

like image 157
Rick Burgess Avatar answered Aug 07 '26 13:08

Rick Burgess



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!