Cannot run `source` in AWS Codebuild

Try using . instead of source. source is not POSIX compliant. ss64.com/bash/source.html


The AWS CodeBuild images ship with a POSIX compliant shell. You can see what's inside the images here: https://github.com/aws/aws-codebuild-docker-images.

If you're using specific shell features (such as source), it is best to wrap your commands in a script file with a shebang specifying the shell you'd like the commands to execute with, and then execute this script from buildspec.yml.

build-script.sh

     #!/bin/bash
      <commands>
      ...

buildspec.yml (snippet)

build: commands: - path/to/script/build-script.sh


CodeBuild now supports bash as your default shell. You just need to specify it in your buildspec.yml.

env:
  shell: bash

Reference: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-syntax