user2297996
user2297996

Reputation: 1584

How to use AWS cli in an docker image?

I'm developing some micro services. I use docker-compose for local testing and I deploy stuff to ECS via copilot.

One of the NodeJS services now requires AWS CLI.

What's the best way to add this?

Dockerfile

FROM node:lts-buster-slim as base

RUN apt-get update
RUN apt-get install -y --no-install-recommends python build-essential curl unzip

RUN curl --insecure "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
RUN unzip awscliv2.zip
RUN ./aws/install

...

RUN npm install

The problem is that AWS CLI cannot find the credentials this way and therefore NPM install fails. How can make the credentials available? I tried to add a volume to docker-compose.yml, but it didn't work.

Can I provide AWS config / credentials as ENV vars somehow? I can't run aws configure in the container, since it requires manual input.

EDIT:

Is there some simple solution? I basically need AWS CLI only because I need to run aws codeartifact login so I can install private NPM packages.

I'm sure creating a task will solve this, isn't there a simpler way? I do everything else via the AWS-SDK and I already have the credentials for that. But this step is required by NPM install, so I must use the CLI.

EDIT2:

Basically I need to run this in the build phase:

aws codeartifact login --tool npm --repository xyz --domain something --region eu-west-1

We have private NPM repo using CodeArtiact. I need to login to use that. But Docker doesn't support ENV vars in Dockerfile, so I don't know how to provide AWS credentials.

Basically that's the only problem.

Upvotes: 9

Views: 18023

Answers (1)

Pistazie
Pistazie

Reputation: 268

There are many options to supply credentials to the CLI. They are documented here with their precedence.

While I am not sure about your specific setup and the best approach with copilot I would try opting for the Environment variables option as it is well supported with docker-compose.

Similarly, the JS-SDK has a credentials chain (reference for V2 here).

Upvotes: 2

Related Questions