1

Situation

Use shell script to push docker images (Nodejs app) to ECR

Command

aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin xxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com

File shell script

#!/bin/sh

docker build -t abc/abc-api ../../abc/abc-api

docker build -t abc/abc-fe ../../abc/abc-fe

aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin xxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com

docker tag abc/abc-api xxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/abc:api-latest

docker push xxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/abc:api-latest

docker tag abc/abc-fe xxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/abc:fe-latest

docker push xxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/abc:fe-latest

Current

  • When run file shell script
Unable to locate credentials. You can configure credentials by running "aws configure".
Error: Cannot perform an interactive login from a non TTY device
  • When run command on terminal
WARNING! Your password will be stored unencrypted in /home/***/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

What I want

Shell script login succeeded

Environment

  • Linux mint 20
  • aws-cli 2.0.46
  • Configured aws authentication by aws configure
18
  • Can you clarify what do you mean by "sell script" and "terminal"? Commented Sep 16, 2020 at 4:16
  • I have just update file shell script and some description Commented Sep 16, 2020 at 4:21
  • When do you execute your shell script? Commented Sep 16, 2020 at 4:28
  • 1
    It show root... Commented Sep 16, 2020 at 5:00
  • 1
    So you are using different user then yourself when you run the command in terminal. This explains why it does not work. Commented Sep 16, 2020 at 5:01

1 Answer 1

1

Based on the comments.

The reason why the script does not work is that it is executed under root user. The root user does not have aws profile defined, which explain why the script errors out with "You can configure credentials by running "aws configure" message.

To rectify the issue, there are some posibilites:

  1. Don't run the script under root user. Run it as your own user, because you have aws profile configure for yourself (preferred).
  2. Create new aws profile for the root user.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.