1

I try to migrate circleci from v1.0 to v2.0.

First I can't install awscli but finally can install it with the code below but got another error that cannot found aws command.

version: 2
    jobs:
      build:
        docker:
          - image: circleci/node:8.9.1
    steps:
      - checkout
      - restore_cache:
          key: dependency-cache-{{ checksum "package.json" }}
  - save_cache:
      key: dependency-cache-{{ checksum "package.json" }}
      paths:
        - node_modules
deploy:
    docker:
      - image: circleci/node:8.9.1
steps:
  - checkout
  - run:
      name: Install yarn
      command: yarn install
  - run:
      name: Install awscli
      command: |
        sudo apt-get install python-pip python-dev
        pip install 'pyyaml<4,>=3.10' awscli --upgrade --user
  - run:
      name: AWS S3
      command: aws s3 sync build s3://<URL> --delete

workflows:
  version: 2
  build-and-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
          filters:
            branches:
              only: master

It show "aws: command not found". I'm not sure that I do something wrong or not but I want to know what's the problem and how to solve it. Thanks.

3 Answers 3

4

I would rework your config. Each job should have a focus/point. For deployment for example, you don't need NodeJS, you need the AWS CLI so use an image for that.

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:8.9.1
    steps:
      - checkout
      - restore_cache:
          key: dependency-cache-{{ checksum "package.json" }}
      - save_cache:
          key: dependency-cache-{{ checksum "package.json" }}
          paths:
            - node_modules
      - persist_to_workspace:
          root: /home/circleci
          paths: project
  deploy:
    docker:
      - image: cibuilds/aws:1.16.1
    steps:
      - checkout
      - attach_workspace:
          at: /home/circleci
      - run:
          name: AWS S3
          command: aws s3 sync build s3://<URL> --delete

workflows:
  version: 2
  build-and-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
          filters:
            branches:
              only: master
1

Try with the following step (taken from their v2 docs);

steps:
  - run:
      name: Install PIP
      command: sudo apt-get install python-pip python-dev
  - run:
      name: Install awscli
      command: sudo pip install awscli
  - run:
      name: Deploy to S3
      command: aws s3 sync build s3://<URL> --delete
1
  • Hmm. Maybe try a step before Install PIP - i've updated my example. Sep 3, 2018 at 10:00
1

This method for installing awscli seems to work fine on a variety of systems. Tested on circleci/openjdk:8-jdk, requires no additional installation.

Edit Seems that the node image lacks the installation of libpython-dev.

##################
# Install AWS CLI
##################

# For node images on Circle, install libpython-dev
sudo apt-get install -y libpython-dev

# Download awscli bundle
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"

# Unzip the downloaded bundle
unzip awscli-bundle.zip

# Run the install script and install to ~/bin/aws directory
./awscli-bundle/install -b ~/bin/aws

After that, to run awscli commands, specify the full path to the aws executable, for example:

~/bin/aws s3 ls

Resources

Helpful thread GitHub

Example GitHub repository with Circle config on node:8.9.1

The CircleCI builds

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.