AWS CodeBuild and S3 deployments

I've been using AWS to host my personal websites (although this website hasn't been relocated there).

I automate everything. Anything not automated is just a POC in my perspective.

I have some static websites - that is websites that do not do any server side processing - all processing is in the users' web browser. In this case, this is a simple website that requires basic hosting and that can be done directly with AWS S3. No other http server or AWS services (Besides domain association through Route 53 which has to do with DNS and not HTTP hosting).

This is prefect for a lot of my needs.

The only need beyond hosting is automated deployment from git. For a react-type project, the high level steps are simply:

  • yarn install
  • yarn test
  • yarn build

Form there, you have your tested and built react project. Now this needs to get to the S3 bucket. This is easy enough to do. AWS CodeBuild hooks up to GitHub and is my automated deployment solution but, I came to a weird problem.

The S3 bucket would contain the build folder and my application would be in there. But I wanted the files to be at the root of the S3 bucket.

artifacts:
  files:
    - 'build/**/*'
  base-directory: .

What I found was actually quite simple but not intuitive because it's a bit backwards in declaration. It makes sense though in the context of AWS.

artifacts:
  files:
    - '**/*'
  base-directory: build

Move the folder as the base-directory and take that out of the files declaration. It's almost like we've cd'd in to build and then deploy the artifacts.

Frank Villasenor

Frank Villasenor

Owner and principal author of this site. Professional Engineering Lead, Software Engineer & Architect working in the Chicagoland area as a consultant. Cert: AWS DevOps Pro
Chicago, IL