Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codebuild aws command not found when ran?

I'm trying to get a simple docker app to build using AWS codebuild, but I am coming across an error where the aws command is not found:

[Container] 2016/12/10 04:29:17 Build started on Sat Dec 10 04:29:17 UTC 2016
[Container] 2016/12/10 04:29:17 Running command echo Building the Docker image...
[Container] 2016/12/10 04:29:17 Building the Docker image...
[Container] 2016/12/10 04:29:17 Running command docker build -t aws-test .
[Container] 2016/12/10 04:29:17 sh: 1: docker: not found
[Container] 2016/12/10 04:29:17 Command did not exit successfully docker build -t aws-test . exit status 127
[Container] 2016/12/10 04:29:17 Phase complete: BUILD Success: false
[Container] 2016/12/10 04:29:17 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker build -t aws-test .. Reason: exit status 127

I've got a super simple docker file which builds a simple express app:

FROM node:6.2.0

# Create app directory
RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/

# Bundle app source
COPY . /usr/src/app

EXPOSE 3000

CMD npm install && npm start

And I've got a super simple buildspec.yml which is suppose to build the docker container and push it to the aws registry:

version: 0.1

phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - $(aws ecr get-login --region us-west-2)
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...          
      - docker build -t <CONTAINER_NAME> .
      - docker tag <CONTAINER_NAME>:latest <ID>.dkr.ecr.us-west-2.amazonaws.com/<CONTAINER_NAME>:latest
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker image...
      - docker push <ID>.dkr.ecr.us-west-2.amazonaws.com/<CONTAINER_NAME>:latest

However once ran, it throws the error posted above ^^ I'm not sure why the aws cli utils aren't found? This guide here:

http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html

Suggests I don't need to do anything to setup the aws cli utils anywhere?

Also one other thing I noticed, I removed $(aws ecr get-login --region us-west-2) step from the buildspec file, built it again and it then said that the docker command was not found?! Have I missed a step somewhere (I don't think I have).

like image 508
James111 Avatar asked Dec 10 '16 04:12

James111


People also ask

Can I use AWS CLI in CodeBuild?

You can work with CodeBuild through the CodeBuild console, AWS CodePipeline, the AWS CLI, or the AWS SDKs.

How do I assume AWS CodeBuild?

CodeBuild uses the CodeBuild service role as the default AWS credential in the build container and Docker runtime. Export the AssumeRole credentials as environment variables. Then, pass these variables into the Docker runtime by using the --build-arg parameter for docker build.

Does CodeBuild use bash?

AWS CodeBuild now supports the bash and CMD shell environments for executing commands and scripts.


1 Answers

So it turned out I was using the wrong environment. Here is what I'm using now:

Now

I was trying to specify my own docker image, which was ultimately not setup with any of the AWS cli utils!

Thanks to @Clare Liguori for tipping me off!

like image 57
James111 Avatar answered Sep 18 '22 15:09

James111