Home > Blockchain >  Using docker for aws command line utility
Using docker for aws command line utility

Time:12-22

This command works as expected:

# docker run --rm -it public.ecr.aws/aws-cli/aws-cli:2.9.1 --version
aws-cli/2.9.1 Python/3.9.11 Linux/5.15.0-1026-aws docker/aarch64.amzn.2 prompt/off

But this does not:

# docker run --rm -it public.ecr.aws/aws-cli/aws-cli:2.9.1 s3 ls
Unable to locate credentials. You can configure credentials by running "aws configure".

Nor can I configure AWS credentials...

# docker run -it public.ecr.aws/aws-cli/aws-cli:2.9.1 aws configure

I am not sure how to use docker for aws command.


Update:

This seems to work as expected:

$ docker run --rm -it -v ~/.aws:/root/.aws  public.ecr.aws/aws-cli/aws-cli:2.9.1 s3 ls

But in my case, I do not have credentials saved locally. Isn't the docker container recommended in such cases?

CodePudding user response:

This command...

docker run --rm -it public.ecr.aws/aws-cli/aws-cli:2.9.1 s3 ls

...does not work because it does not have access to either your AWS configuration in $HOME/.aws nor to environment variables such as $AWS_ACCESS_KEY_ID and $AWS_SECRET_ACCESS_KEY.

If you have your credentials in environment variables, you can expose them to the container using the -e option to docker run:

docker run --rm -it -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY \
  public.ecr.aws/aws-cli/aws-cli:2.9.1 s3 ls

Alternatively, you can expose your ~/.aws directory as you have shown in your recent edit to your answer:

docker run --rm -it -v ~/.aws:/root/.aws \
  public.ecr.aws/aws-cli/aws-cli:2.9.1 s3 ls
  • Related