LoginSignup
27
9

More than 3 years have passed since last update.

AWS ECRでAWS CLIの認証で弾かれた問題

Posted at

なにこれ

AWSのECRへ認証するコマンドを叩いた時に、下記のエラーが発生したのでその対策

エラー文

auth error An error occurred (UnrecognizedClientException) when calling the GetAuthorizationToken operation: The security token included in the request is invalid. Error: Cannot perform an interactive login from a non TTY device

訳)auth error GetAuthorizationToken操作の呼び出し中にエラーが発生しました(UnrecognizedClientException):要求に含まれているセキュリティトークンが無効です。エラー:TTY以外のデバイスからインタラクティブログインを実行できません

はい、訳を読んでも意味が分からないです。
セキュリティートークンが無効だから、認証系の問題かな?と予想。
とりあえず、エラー文をはっつけて検索する初歩的な方法をしました。

原因

AWSのACCESS_KEYとSECRET_KEYの情報が一致しないため(?)

原因を調べる

aws configure listコマンドを叩いて、アクセスキーとシークレットキーが何と設定されてるか確認します。

~ $ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************1234             env    
secret_key     ****************1234             env    
    region           ap-northeast-1      config-file    ~/.aws/config

ここで本来あって欲しいアクセスキーとシークレットキーになっていないことに気づく。

なので、下記のコマンドで変更する

export AWS_ACCESS_KEY_ID=****5678
export AWS_SECRET_ACCESS_KEY=****5678

このコマンドで、~/.zshrc

再度aws configure listを叩いてキー2つを確認する。

~ $ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************5678             env    
secret_key     ****************5678             env    
    region           ap-northeast-1      config-file    ~/.aws/config

ターミナルを再起動後、もう1回ECRへ認証するコマンドを叩いたら、成功しました!

27
9
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
27
9