AWS command not found. Jekyll Deployment with automatic invalidaton

So I am trying to automatically create an invalidation on AWS but get AWS: Command not found. Here is my config file below.

defaults: &defaults
  working_directory: ~/repo
version: 2
jobs:
  build:
    <<: *defaults
    docker:
      - image: circleci/ruby:2.5
    environment:
      BUNDLE_PATH: ~/repo/vendor/bundle
    steps:
      - checkout
      - restore_cache:
          keys:
            - rubygems-v1-{{ checksum "Gemfile.lock" }}
            - rubygems-v1-fallback
      - run:
          name: Bundle Install
          command: bundle check || bundle install
      - save_cache:
          key: rubygems-v1-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle
      - run:
          name: Jekyll build
          command: bundle exec jekyll build
      - run:
          name: HTMLProofer tests
          command: |
            bundle exec htmlproofer ./_site \
              --allow-hash-href \
              --check-html \
              --disable-external
      - persist_to_workspace:
          root: ./
          paths:
            - _site
  deploy:
    <<: *defaults
    docker:
      - image: circleci/python:3.6.3
    environment:
      S3_BUCKET_NAME: NAME GOES HERE
    steps:
      - attach_workspace:
          at: ./
      - run:
          name: Install AWS CLI
          command: pip install awscli --upgrade --user
      - run:
          name: Upload to s3
          command: ~/.local/bin/aws s3 sync ./_site s3://NAMEGOESHERE/ --delete --acl public-read
      # ACTIVATE CLOUD FRONT CLI
      - run:
          name: activate cloud front
          command: |
                  aws configure set preview.cloudfront true
                  aws configure set preview.create-invalidation true
      # Invalidate Cloudfront
      - run:
          name: Invalidate Cloudfront
          command: aws cloudfront create-invalidation --distribution-id MYID --paths /\*
workflows:
  version: 2
  test-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
          filters:
            branches:
              only: master

I will be honest that this is my first attempt at this so apologies for the noob code. Error code I get is this.

#!/bin/bash -eo pipefail
aws configure set preview.cloudfront true
aws configure set preview.create-invalidation true

/bin/bash: aws: command not found
Exited with code 127

Everything else works. When I make changes the S3 bucket automatically updates. Just does not create a new invalidation.

So I found the AWS command by adding the correct path. Thank goodness but I am now at this new error. I replaced any sensitive info with Key and MYID.

#!/bin/bash -eo pipefail
    ~/.local/bin/aws cloudfront create-invalidation --distribution-id MYID --paths /\*


    An error occurred (AccessDenied) when calling the CreateInvalidation operation: User: arn:aws:iam::KEY:user/ohmni-template-PublishUser-KEY is not authorized to perform: cloudfront:CreateInvalidation
    Exited with code 255

So is it really the config file here or something I am missing either in CircleCI or AWS? Has anyone seen this error before?

Turns out it was permissions for my IAM user on AWS. I gave it CloudfrontFullAccess and it worked! For those interested, there was an article that helped me.

https://medium.freecodecamp.org/how-to-set-up-continuous-deployment-to-aws-s3-using-circleci-in-under-30-minutes-a8e268284098

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.