Home > Software design >  AWS environment variables does not work with ECR get-login
AWS environment variables does not work with ECR get-login

Time:02-03

Am I configuring environment variables for the default user, but it does not work with aws ecr get-login why?

> export AWS_ACCESS_KEY_ID=SOMEID
> export AWS_SECRET_ACCESS_KEY=SOMEID
> sudo aws ecr get-login --no-include-email --region eu-west-1

This gives the error:

Unable to locate credentials. You can configure credentials by running "aws configure".

Using AWS configure resolves the issue. However, I would like to use environment variables instead.

  • Using Oracle Linux
  • I can see the environment variables are set and correct using env

CodePudding user response:

By default, sudo doesn't pass your local environment variables to the root process it spawns. You have to tell it to pass those environment variables to the process with the --preserve-env argument.

Or just set the values on the same command:

sudo AWS_ACCESS_KEY_ID=SOMEID AWS_SECRET_ACCESS_KEY=SOMEID aws ecr get-login --no-include-email --region eu-west-1
  •  Tags:  
  • Related