A very simple buildspec.yml using a shell script to fetch an environment file from S3. You’ll want to make sure permissions are setup on the S3 bucket to properly manage this from CodeBuild.

Usage

We’re assuming the environment files are all in the same S3 bucket, and they’re named environment.config. For example dev.config and prod.config and then are pulled into the source code and renamed .env for the application to consume.

bash /path/to/init.sh --env=prod --region=us-west-2

The Buildspec

Below is a buildspec that is noticeably not executing tests or anything pre_build as it should. Do not do that for a production build!