Run integration tests against LocalStack without a .env file

How can I load secrets from AWS Parameter Store in integration tests without a .env file? Run the test command through envilder exec against LocalStack. Start LocalStack, seed the parameters with envilder --push, point the AWS SDK at it with AWS_ENDPOINT_URL and dummy credentials, then run envilder exec -- followed by npm test, dotnet test or pytest. Envilder reads every parameter listed in a map file from the Parameter Store emulated by LocalStack and starts your tests with them as environment variables. It writes no .env file, and if a parameter is missing it exits with 125 without running a single test.

How it works

  1. LocalStack runs an emulator of AWS Systems Manager Parameter Store (SSM) in a Docker container, with its gateway on port 4566.
  2. Envilder reads a map file and calls ssm:GetParameter, with decryption, once per variable. The AWS SDK inside Envilder sends those calls to LocalStack because AWS_ENDPOINT_URL points there.
  3. Envilder starts your test command with the values in its environment. If any parameter is missing, empty or unreadable, the command does not start and Envilder exits with 125.
  4. In this mode Envilder reads and writes no .env file.

Prerequisites

  • Docker, to run LocalStack.
  • Node.js 22.12 or later, because the Envilder CLI is a Node.js package. This applies to .NET and Python projects too: only the test command is yours. Install the CLI with npm install -g envilder, or prefix the envilder commands below with npx.
  • A test command that reads its configuration from environment variables, such as npm test, dotnet test or pytest.

Start LocalStack

Start the container and publish the gateway port. The auth token is passed from your shell without being written in the command:

docker run -d --name localstack -p 127.0.0.1:4566:4566 -e LOCALSTACK_AUTH_TOKEN localstack/localstack

The same with Docker Compose:

compose.yamlyaml
services:
  localstack:
    image: localstack/localstack
    ports:
      - "127.0.0.1:4566:4566"
    environment:
      LOCALSTACK_AUTH_TOKEN: ${LOCALSTACK_AUTH_TOKEN}
⚠️
Recent LocalStack images do not start without an auth token. When this guide was written, localstack/localstack and localstack/localstack:stable (version 2026.10.7) exited at startup with License activation failed. LocalStack announced the change with the 2026.03.0 release, and CI runs need a CI auth token. Check the LocalStack pricing page for the plan that fits your use.

Releases published before that change still start without a token. The output on this page was produced with localstack/localstack:4.14.0, started with docker run and no token. It predates the change, so treat it as a stopgap rather than a default.

LocalStack answers on http://127.0.0.1:4566/_localstack/health when it is ready.

Point Envilder at LocalStack

Envilder has no LocalStack option, and the map file has no endpoint field: $config accepts only provider, vaultUrl and profile. Envilder passes no endpoint to its AWS client, so the AWS SDK for JavaScript that the CLI uses applies its own resolution, and that reads AWS_ENDPOINT_URL from the environment. Set four variables in the shell that runs Envilder:

  • AWS_ENDPOINT_URL: the LocalStack gateway, http://127.0.0.1:4566.
  • AWS_REGION: any region. Seeding and reading must use the same one, because parameters are stored per region. Envilder reads AWS_REGION first, then AWS_DEFAULT_REGION, and ends at us-east-1 when it finds neither. The examples also set AWS_DEFAULT_REGION to the same value, because some SDKs your tests use (such as boto3) read only that one.
  • AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY: dummy values such as test. LocalStack accepts any credentials, but the SDK still needs some.

In bash or zsh:

export AWS_ENDPOINT_URL=http://127.0.0.1:4566
export AWS_REGION=us-east-1
export AWS_DEFAULT_REGION=us-east-1
export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test

In PowerShell:

$env:AWS_ENDPOINT_URL = 'http://127.0.0.1:4566'
$env:AWS_REGION = 'us-east-1'
$env:AWS_DEFAULT_REGION = 'us-east-1'
$env:AWS_ACCESS_KEY_ID = 'test'
$env:AWS_SECRET_ACCESS_KEY = 'test'
⚠️
Set all four in the same shell. Without AWS_ENDPOINT_URL, Envilder calls real AWS with the dummy credentials and fails with The security token included in the request is invalid. Keep the dummy credentials anyway: a typo in the endpoint can then never reach a real account.

In Git Bash on Windows, an argument that starts with / such as --secret-path=/my-app/test/db-password is rewritten into a Windows path before Envilder sees it, and the map file ends up with a C:/Program Files/Git/... path. Set MSYS_NO_PATHCONV=1 first, or use PowerShell.

Seed the test parameters

Write the values Envilder will read. One push per variable creates the parameter in LocalStack and records the mapping in the map file, so you do not write it by hand. --push is written out although a push with --key, --value and --secret-path does not need it:

envilder --push --provider=aws --map=envilder.test.json --key=DB_PASSWORD --value=local-db-password-1234 --secret-path=/my-app/test/db-password
envilder --push --provider=aws --map=envilder.test.json --key=API_TOKEN --value=local-api-token-5678 --secret-path=/my-app/test/api-token

Each push prints the value and the path with asterisks and keeps only their last three characters:

⭐ SECRET PUSHED  —  DB_PASSWORD=*******************234 → *********************ord
✓ Created envilder.test.json

⭐ SECRET PUSHED  —  API_TOKEN=*****************678 → *******************ken
✓ Added API_TOKEN to envilder.test.json

The map file now holds the two mappings:

envilder.test.jsonjson
{
  "DB_PASSWORD": "/my-app/test/db-password",
  "API_TOKEN": "/my-app/test/api-token"
}

--map=envilder.test.json and --provider=aws are written out on purpose. With an explicit --map, a push creates this file and never touches an envilder.json your project already has. Pushing a variable that is already mapped leaves the file as it is.

The map file holds parameter names, not values: commit it, so your team and CI use the same one. The values exist only inside the container, so they are gone when you remove it. Seed again at the start of each run. envilder push reference: single-secret push

Run the tests with envilder exec

Put envilder exec in front of the test command, with the same --map and --provider. Everything after -- is your command:

envilder exec --provider=aws --map=envilder.test.json -- npm test
envilder exec --provider=aws --map=envilder.test.json -- dotnet test
envilder exec --provider=aws --map=envilder.test.json -- pytest

To see what a command receives, run one that prints which variables are set, never their values:

envilder exec --provider=aws --map=envilder.test.json -- node -e "for (const n of ['DB_PASSWORD','API_TOKEN']) console.log(n, process.env[n] ? 'is set' : 'is missing')"
envilder: 2 secrets resolved (aws) → node …
DB_PASSWORD is set
API_TOKEN is set

The first line is Envilder on stderr, the rest is your command. Run the same script without Envilder and both variables are reported as missing: the shell never had them.

Your command inherits the whole environment of the shell, including AWS_ENDPOINT_URL and the dummy credentials. A test that creates its own AWS client in the same process also talks to LocalStack, as long as its SDK reads AWS_ENDPOINT_URL. The .NET and Python SDK acceptance tests of this repository use the same variable.

--provider=aws overrides $config.provider and --map picks the file, so a leftover envilder.json in the folder, or a map file that names Azure, cannot change what this command reads.

Envilder exits with the exit code of your command, so a failing test fails the step or the script that called it. Exit code 125 is Envilder itself: it could not start your command.

A missing secret stops the run

Exec mode is fail-closed. If the map file lists a parameter that was never seeded, here STRIPE_KEY, the command does not start:

🪙  RESOLVING SECRETS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✓ DB_PASSWORD         → *******************234

💥 GAME OVER — some secrets could not be fetched
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✗ STRIPE_KEY          → ********************key

  ⮕ WHY?
     not found

The exit code is 125. Your tests never run with a half-configured environment, which is the failure that otherwise shows up as a confusing null reference or a missing key deep inside a test.

⚠️
In exec mode Envilder reads and writes no .env file: the values are resolved once, in memory, and handed to your command through its environment. That covers Envilder only. Your tests, or a tool they start, can still write the values wherever they want.

Run it in GitHub Actions

A service container starts LocalStack next to the job. The variables are set at job level, so every step, including the tests, sees them. The AWS credentials are dummy values: no OIDC role is involved, because nothing reaches a real account:

.github/workflows/integration-tests.ymlyaml
name: Integration tests

on: [push]

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      localstack:
        image: localstack/localstack
        ports:
          - 4566:4566
        env:
          LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
    env:
      AWS_ENDPOINT_URL: http://localhost:4566
      AWS_REGION: us-east-1
      AWS_DEFAULT_REGION: us-east-1
      AWS_ACCESS_KEY_ID: test
      AWS_SECRET_ACCESS_KEY: test
    steps:
      - uses: actions/checkout@v7

      - uses: actions/setup-node@v7
        with:
          node-version: 22.x

      - run: npm ci

      # Wait until LocalStack answers
      - run: curl --silent --fail --retry 30 --retry-delay 2 --retry-connrefused $AWS_ENDPOINT_URL/_localstack/health

      # Seed the test parameters
      - run: |
          npx envilder --push --provider=aws --map=envilder.test.json --key=DB_PASSWORD --value=local-db-password-1234 --secret-path=/my-app/test/db-password
          npx envilder --push --provider=aws --map=envilder.test.json --key=API_TOKEN --value=local-api-token-5678 --secret-path=/my-app/test/api-token

      # Run the tests with the secrets in their environment
      - run: npx envilder exec --provider=aws --map=envilder.test.json -- npm test
  • The service reads LOCALSTACK_AUTH_TOKEN from a repository secret. Use a CI auth token, and pin the image tag in your own workflow so a new LocalStack release cannot change your pipeline.
  • This workflow was written from the GitHub Actions and LocalStack documentation and the commands above. Unlike the local flow, it was not run on a hosted runner while writing this guide.
  • npx envilder downloads the latest published CLI unless you pin one with npx envilder@<version>.

For tests that read real SSM parameters in a pipeline, with OIDC instead of dummy credentials, see the GitHub Actions guide.

The in-process alternative: Testcontainers and the SDKs

If your code calls the Envilder SDK instead of reading environment variables, start LocalStack from the tests themselves. The macalbert/envilder-examples repository has one example per runtime, each with tests for AWS SSM against LocalStack and for Azure Key Vault against LocalStack for Azure:

  • Testcontainers starts and stops the emulators from the test run, so there is no docker run step and no seed command.
  • The tests build the cloud client themselves, aimed at the emulator, and hand it to the Envilder client. Everything after that line is the code your app runs.
  • The examples fetch the LocalStack auth token with Envilder from your own AWS account and pass it to the containers, so no token sits in a .env file or in the pipeline.

Use envilder exec when your application reads environment variables and you want no change in test code. Use the SDK and Testcontainers when the application itself resolves a map file and you want the tests to own the emulator lifecycle.

Common errors

MessageFix
The security token included in the request is invalid.The request reached real AWS. AWS_ENDPOINT_URL is not set in the shell that runs Envilder, or it is set in another terminal.
connect ECONNREFUSED 127.0.0.1:4566Nothing listens on that address. LocalStack is not running, is still starting, or publishes another port. Check docker ps and the health URL.
Could not load credentials from any providersNo credentials reached Envilder. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, even to dummy values.
not foundThe parameter was not seeded in this LocalStack, or was seeded in another region. Seed it again, and compare the path and AWS_REGION with the push.

The full list of exit codes and messages is in the envilder exec reference.