Travis CI

Use LocalStack in Travis CI

This guide shows how to start and use LocalStack in your Travis CI jobs.

Setting up the Travis CI job

When you want to integrate LocalStack into your job configuration, you just have to execute the following steps:

  • Install the LocalStack CLI (and maybe also awslocal).
  • Make sure your LocalStack docker image is up-to-date by pulling the latest version.
  • Use the LocalStack CLI to start LocalStack. Make sure to use the -d flag to start the LocalStack docker container in detached mode.
  • Wait for the container to report that it is up and running.

The following example Travis CI job config (.travis.yaml) executes these steps, creates a new S3 bucket, and prints a nice message in the end:

  1. language: python
  2. services:
  3. - docker
  4. python:
  5. - "3.8"
  6. before_install:
  7. # Install the LocalStack CLI and awslocal
  8. - python -m pip install localstack awscli-local[ver1]
  9. # Make sure to pull the latest version of the image
  10. - docker pull localstack/localstack
  11. # Start LocalStack in the background
  12. - localstack start -d
  13. # Wait 30 seconds for the LocalStack container to become ready before timing out
  14. - echo "Waiting for LocalStack startup..."
  15. - localstack wait -t 30
  16. - echo "Startup complete"
  17. script:
  18. # Test LocalStack by creating a new S3 bucket (and verify that it has been created by listing all buckets)
  19. - awslocal s3 mb s3://test
  20. - awslocal s3 ls
  21. - echo "Execute your tests here :)"

Activate LocalStack Pro

You can easily enable LocalStack Pro by adding your API key to the project’s environment variables. The LocalStack CLI will automatically pick it up and activate the Pro features.

Just go to the project settings in Travis CI (More optionsSettings), scroll down to the Environment Variables section, and add your API key:

Adding the LocalStack API key in Travis CI

Last modified November 24, 2021: update CI examples to use localstack>=0.13.0.1 CLI features (03ff7715)