LoginSignup
139
72

More than 3 years have passed since last update.

AWS CLIでECRにログインする時はget-loginではなくget-login-passwordを使おう

Last updated at Posted at 2020-02-11

aws ecr get-login は非推奨に

コマンドリファレンスに記載されています。

Note: This command is deprecated. Use get-login-password instead.

AWS CLI Command Reference - get-login
https://docs.aws.amazon.com/cli/latest/reference/ecr/get-login.html

aws ecr get-login コマンドの出力結果は以下のようになります。

$ aws ecr get-login --no-include-email
docker login -u AWS -p <password> https://<aws_account_id>.dkr.ecr.<region>.amazonaws.com

docker login コマンド全体が標準出力されるため便利ではあるのですが
そのまま実行してしまうと、パスワードがシェルのhistoryやログファイルに
残ってしまうというリスクがあります。

aws ecr get-login-password を使う

AWS CLI Command Reference - get-login-password
https://docs.aws.amazon.com/cli/latest/reference/ecr/get-login-password.html

aws ecr get-login-password コマンドはログイン用のパスワードのみが標準出力されます。

$ aws ecr get-login-password
<password>

docker login コマンドは --password-stdin というオプションが利用可能で
パスワードを標準入力から読み込ませることができます。
以下のように aws ecr get-login-password の結果を渡すことで、
履歴やログにパスワードを残さず済みます。

$ aws ecr get-login-password | docker login --username AWS --password-stdin https://<aws_account_id>.dkr.ecr.<region>.amazonaws.com
Login Succeeded

Provide a password using STDIN
https://docs.docker.com/engine/reference/commandline/login/#provide-a-password-using-stdin

利用可能なAWS CLIのバージョン

get-login-password コマンドは AWS CLI Version 1.17.10 以降、
または2020/2/10にGAとなった Version 2で利用することができます。

注意点としては AWS CLI Version 2では get-loginコマンドは削除されているため利用できません。
Version 1.17.10 以降では 下位互換性のため、引き続き利用可能です。

The older aws ecr get-login command is still available in the AWS CLI version 1 for backward compatibility.

Breaking Changes – Migrating from AWS CLI version 1 to version 2
AWS CLI version 2 replaces ecr get-login with ecr get-login-password
https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html#cliv2-migration-ecr-get-login

以上です。
参考になれば幸いです。

139
72
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
139
72