Having problems accessing AWS credentials with awscli

awscli
aws
s3
circle.yml

#1

I am trying to run a command to sync a local directory with an AWS S3 bucket. Here are the steps I am using:

  1. I created an IAM user specifically for my CircleCi account that can currently access all AWS S3 buckets and perform all actions.

  2. I tested the credentials in the AWS Policy Simulator and also tested with the awscli on my local machine. All tests passed and showed the IAM user as having access.

  3. I saved the AWS Access Key ID and AWS Secret Access Key into the AWS Permissions section of my project

  4. I wrote up a deploy script in my deploy_staging.sh file with these instructions:

DEFAULT="default"
PROFILE=${AWS_PROFILE:-$DEFAULT}
BUCKET=bucket-name
DIR=./dist
aws s3 sync $DIR s3://$BUCKET/
  1. I set up a circle.yml file to run the script for the necessary branches:
machine:
  node:
    version:  5.1.1

dependencies:
  override:
    - sudo pip install awscli

test:
  override:

deployment:
  staging:
    branch: master
    commands:
    - ./deploy_staging.sh
  production:
    branch: production
    commands:
    - ./deploy_production.sh

However, when I deploy to Github with my master branch–and everything seems to try to execute as it should–I receive this error message when the sync command is run:

./deploy_staging.sh

./deploy_staging.sh returned exit code 126

bash: line 1: ./deploy_staging.sh: Permission denied Action failed: ./deploy_staging.sh

I haven’t found much, instruction-wise, for accessing the AWS credentials in the CircleCi environment other than this method, but this seems to work easily on my local Mac OSX environment (the instructions in deploy_staging.sh, that is).

What is the trick for getting the correct permissions to run the deploy_staging.sh instructions?


#2

So I seem to have figured out the permission issue, which was not related to AWS at all.

I added this line to the circle.yml file to set permissions on the script file and things executed as desired:

- chmod +x ./deploy_staging.sh

So here is my circle.yml file, as of now:

machine:
  node:
    version:  5.1.1

dependencies:
  override:
    - sudo pip install awscli

deployment:
  staging:
    branch: master
    commands:
    - chmod +x ./deploy_staging.sh
    - ./deploy_staging.sh
  production:
    branch: production
    commands:
    - chmod +x ./deploy_production.sh
    - ./deploy_production.sh

and here’s a working version of my script file:

#!/usr/bin/env bash
DEFAULT="default"
PROFILE=${AWS_PROFILE:-$DEFAULT}
BUCKET=allaboardapps-site-staging
DIR=./dist
aws s3 sync $DIR s3://$BUCKET/

#3