DEV Community

rahulbhave
rahulbhave

Posted on • Edited on

Running Tests against LocalStack using GitHub action

My Workflow

This workflow I designed to run tests against LocalStack. I hope this Github action will help developer community or testers to test their respective test cases against LocalStack instead of executing it against the AWS Cloud which could be costly in some cases. For sample Lambda tests, I have referred This Repo.

This github action flow is very simple and consists of following three steps-

Step 1
Running localstack services.

Step 2
Install python and other test dependencies

Step 3
Run the tests against LocalStack

The details such as Yaml file and Link to code are given below

Submission Category:

DIY Deployments

Yaml File or Link to Code

Yaml file

name: Localstack CI
on: push
jobs:
  localstack:
    runs-on: ubuntu-latest
    services:
      localstack:
        image: localstack/localstack:latest
        env:
          SERVICES: lambda
          DEFAULT_REGION: eu-west-1
          AWS_ACCESS_KEY_ID: localkey
          AWS_SECRET_ACCESS_KEY: localsecret
        ports:
          - 4566:4566
          - 4571:4571
    steps:
      - uses: actions/checkout@v2
      - name: Install Python 3.8
        uses: actions/setup-python@v1
        with:
          python-version: 3.8
      - name: Install dependencies
        run: |
          pip3 install --upgrade pip==20.0.1
          pip3 install -r requirements.txt
      # Execute Tests lambda
      - name: Run test for sample lambda
        run: |
          cd lambda
          pytest -sv

Enter fullscreen mode Exit fullscreen mode

Link to GitHub Repo

Additional Resources / Info

I have referred following projects to create the github action-
LocalStack
Testing Lambda with Pytest

Top comments (0)