Using AWS Mock Credentials for your unit tests in Travis

Add a heading

Sometimes you want to run unit tests that require credentials to AWS, you may not have those off hand, or may just want to run the unit tests in question without AWS. This allows you to run mock credentials for key AWS functionalities, let’s see how we can set this up in Travis.


Some pre-requesites we need to tell Travis to fetch in our .travis.yml file, things like MongoDB, and Node, here’s my .travis.yml file for your usage:

language: node_js
    - EC2_REGION=eu-west-1
    - AWS_S3_BUCKET="mock-montana-build"
    - AWS_S3_BUCKET=ecs-refarch-cloudformation
    - SERVER_USER=ec2-user
    - SERVER_USER=ec2-user 
sudo: required
    - '8'
    - '6'
  - mongodb

As you can tell I’ve added mongodb to our services, with various environments that refer to AWS. Now let’s try and run the build, for reference here’s my GitHub repository. In there you’ll see my Travis build logs, some of the JavaScript I coded out, and a few things relating to JavaScript promises.

When your build is successful you should see in your build log something like this:


This means the mock AWS credentials have worked and you can run your unit tests using mock AWS credentials.


You can now run unit tests when you sometimes don’t have those AWS environment variables off hand. As always, if you have any questions, please email me for help/and or if you need assistance with this tutorial.

Happy building!