ECR Login Errorが出た時

  • aws cli を使用し、aws ecr get-login-password コマンドを実行すると以下のエラーとなりました。対処方法を記載します。
    • Error: Cannot perform an interactive login from a non TTY device
niikawa@niikawa1:~$ aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin 111111111111.dkr.ecr.ap-northeast-1.amazonaws.com
usage: aws [options]   [ ...] [parameters]
To see help text, you can run:

  aws help
  aws  help
  aws   help
aws: error: argument operation: Invalid choice, valid choices are:

batch-check-layer-availability           | batch-delete-image
batch-get-image                          | complete-layer-upload
create-repository                        | delete-lifecycle-policy
delete-registry-policy                   | delete-repository
delete-repository-policy                 | describe-image-scan-findings
describe-images                          | describe-registry
describe-repositories                    | get-authorization-token
get-download-url-for-layer               | get-lifecycle-policy
get-lifecycle-policy-preview             | get-registry-policy
get-repository-policy                    | initiate-layer-upload
list-images                              | list-tags-for-resource
put-image                                | put-image-scanning-configuration
put-image-tag-mutability                 | put-lifecycle-policy
put-registry-policy                      | put-replication-configuration
set-repository-policy                    | start-image-scan
start-lifecycle-policy-preview           | tag-resource
untag-resource                           | upload-layer-part
get-login                                | wait
help
Error: Cannot perform an interactive login from a non TTY device

 

aws ecr get-login-password コマンドがエラーになった時の対処

  • aws cli のバージョンが古いため、エラーになった様です。aws cli をアップデートすると解消されました。
  • 現在のバージョンを確認すると、awscli (1.16.54) でした。
niikawa@niikawa1:~$ aws --version
aws-cli/1.16.54 Python/3.6.9 Linux/5.4.72-microsoft-standard-WSL2 botocore/1.20.29

niikawa@niikawa1:~$ sudo pip3 list | grep aws
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
aws-mfa (0.0.12)
awscli (1.16.54)
awslogs (0.10.0)

 

  • pip3 install -U コマンドを使用し、aws cli をアップデートします。
niikawa@niikawa1:~$ sudo pip3 install -U awscli
The directory '/home/niikawa/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/niikawa/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting awscli
  Downloading https://files.pythonhosted.org/packages/6c/48/8cf68d31f3f8606904acc4d98965a2c020acd5e1b9a821b8a7fafdbbc81a/awscli-1.24.10-py3-none-any.whl (3.9MB)
    100% |????????????????????????????????| 3.9MB 479kB/s
Collecting s3transfer<0.6.0,>=0.5.0 (from awscli)
  Downloading https://files.pythonhosted.org/packages/7b/9c/f51775ebe7df5a7aa4e7c79ed671bde94e154bd968aca8d65bb24aba0c8c/s3transfer-0.5.2-py3-none-any.whl (79kB)
    100% |????????????????????????????????| 81kB 12.9MB/s
Collecting botocore==1.26.10 (from awscli)
  Downloading https://files.pythonhosted.org/packages/09/b8/794e0bd260198538ded90c26b353ddb632eab01950d4e7e2e2b8ee510d12/botocore-1.26.10-py3-none-any.whl (8.8MB)
    100% |????????????????????????????????| 8.8MB 180kB/s
Collecting colorama<0.4.5,>=0.2.5 (from awscli)
  Downloading https://files.pythonhosted.org/packages/44/98/5b86278fbbf250d239ae0ecb724f8572af1c91f4a11edf4d36a206189440/colorama-0.4.4-py2.py3-none-any.whl
Collecting rsa<4.8,>=3.1.2 (from awscli)
  Downloading https://files.pythonhosted.org/packages/e9/93/0c0f002031f18b53af7a6166103c02b9c0667be528944137cc954ec921b3/rsa-4.7.2-py3-none-any.whl
Collecting docutils<0.17,>=0.10 (from awscli)
  Downloading https://files.pythonhosted.org/packages/81/44/8a15e45ffa96e6cf82956dd8d7af9e666357e16b0d93b253903475ee947f/docutils-0.16-py2.py3-none-any.whl (548kB)
    100% |????????????????????????????????| 552kB 3.1MB/s
Collecting PyYAML<5.5,>=3.10 (from awscli)
  Downloading https://files.pythonhosted.org/packages/7a/5b/bc0b5ab38247bba158504a410112b6c03f153c652734ece1849749e5f518/PyYAML-5.4.1-cp36-cp36m-manylinux1_x86_64.whl (640kB)
    100% |????????????????????????????????| 645kB 2.5MB/s
Requirement already up-to-date: jmespath<2.0.0,>=0.7.1 in /home/niikawa/.local/lib/python3.6/site-packages (from botocore==1.26.10->awscli)
Collecting python-dateutil<3.0.0,>=2.1 (from botocore==1.26.10->awscli)
  Downloading https://files.pythonhosted.org/packages/36/7a/87837f39d0296e723bb9b62bbb257d0355c7f6128853c78955f57342a56d/python_dateutil-2.8.2-py2.py3-none-any.whl (247kB)
    100% |????????????????????????????????| 256kB 6.5MB/s
Collecting urllib3<1.27,>=1.25.4 (from botocore==1.26.10->awscli)
  Downloading https://files.pythonhosted.org/packages/c5/05/c214b32d21c0b465506f95c4f28ccbcba15022e000b043b72b3df7728471/urllib3-1.26.16-py2.py3-none-any.whl (143kB)
    100% |????????????????????????????????| 143kB 9.7MB/s
Collecting pyasn1>=0.1.3 (from rsa<4.8,>=3.1.2->awscli)
  Downloading https://files.pythonhosted.org/packages/14/e5/b56a725cbde139aa960c26a1a3ca4d4af437282e20b5314ee6a3501e7dfc/pyasn1-0.5.0-py2.py3-none-any.whl (83kB)
    100% |????????????????????????????????| 92kB 13.7MB/s
Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.1->botocore==1.26.10->awscli)
  Downloading https://files.pythonhosted.org/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, urllib3, botocore, s3transfer, colorama, pyasn1, rsa, docutils, PyYAML, awscli
  Found existing installation: six 1.15.0
    Uninstalling six-1.15.0:
      Successfully uninstalled six-1.15.0
  Found existing installation: python-dateutil 2.8.1
    Uninstalling python-dateutil-2.8.1:
      Successfully uninstalled python-dateutil-2.8.1
  Found existing installation: urllib3 1.26.4
    Uninstalling urllib3-1.26.4:
      Successfully uninstalled urllib3-1.26.4
  Found existing installation: botocore 1.20.29
    Uninstalling botocore-1.20.29:
      Successfully uninstalled botocore-1.20.29
  Found existing installation: s3transfer 0.3.4
    Uninstalling s3transfer-0.3.4:
      Successfully uninstalled s3transfer-0.3.4
  Found existing installation: colorama 0.3.7
    Not uninstalling colorama at /usr/lib/python3/dist-packages, outside environment /usr
  Found existing installation: pyasn1 0.4.2
    Not uninstalling pyasn1 at /usr/lib/python3/dist-packages, outside environment /usr
  Found existing installation: rsa 3.4.2
    Uninstalling rsa-3.4.2:
      Successfully uninstalled rsa-3.4.2
  Found existing installation: docutils 0.14
    Uninstalling docutils-0.14:
      Successfully uninstalled docutils-0.14
  Found existing installation: PyYAML 3.12
    Not uninstalling pyyaml at /usr/lib/python3/dist-packages, outside environment /usr
  Found existing installation: awscli 1.16.54
    Uninstalling awscli-1.16.54:
      Successfully uninstalled awscli-1.16.54
Successfully installed PyYAML-5.4.1 awscli-1.24.10 botocore-1.26.10 colorama-0.4.4 docutils-0.16 pyasn1-0.5.0 python-dateutil-2.8.2 rsa-4.7.2 s3transfer-0.5.2 six-1.16.0 urllib3-1.26.16

 

  • 再度aws cli のバージョンを確認します。awscli (1.24.10) にアップデートされました。
niikawa@niikawa1:~$ sudo pip3 list | grep aws
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
aws-mfa (0.0.12)
awscli (1.24.10)
awslogs (0.10.0)

 

  • aws ecr get-login-password コマンドの実行も成功しました。
niikawa@niikawa1:~$ aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin 111111111111.dkr.ecr.ap-northeast-1.amazonaws.com
WARNING! Your password will be stored unencrypted in /home/niikawa/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded