The test harness for AI-generated infrastructure. Deterministic. Time-travel debuggable. API-call cost metered.
Substrate is an event-sourced AWS emulator for testing the infrastructure code that drives AWS — CloudFormation, CDK, Terraform, and any SDK or CLI call — deterministically, offline, and with API-call cost metering, before you deploy to a real account.
It models what is observable through an AWS API call — request/response shapes, resource state and how it transitions over a simulated clock, error codes, and seedable outcomes — not what software inside a resource does. It never runs your user-data, your Lambda code, an inference, or a training job; those are recorded as intent with a seedable result. That boundary is what makes every run reproducible: API observations can be recorded as events and replayed identically, whereas a real workload's timing, scheduling, and I/O cannot.
Use it three ways:
- As a server — run
substrate, point any AWS SDK/CLI athttp://localhost:4566. This is how most consumers use it. - As a Go test harness —
import ".../emulator", spin up an in-process server or deploy a CloudFormation template directly, no HTTP needed. - As a pytest plugin — the
pytest-substratepackage (inpython/) gives a session-scoped server fixture with per-test state reset and boto3 wired to the emulator automatically. It is installed from source until it is published to PyPI (#1616):pip install "git+https://github.com/scttfrdmn/substrate.git#subdirectory=python", orpip install ./pythonfrom a checkout.
AI generates infrastructure code → ??? → Deploy to AWS → $$$
^
This is where you find out
AI generates infrastructure code at volume, inside generate → test → fix loops. That changes what a test harness has to do — and it's where most AWS emulators fall down.
A generate-and-verify loop has needs a human-paced workflow doesn't:
- Determinism, because flakes mislead the loop. A non-deterministic failure is a false signal an agent acts on — wasting fix cycles chasing timing noise. Substrate records every request as an immutable event over a simulated clock, so a failing run is real and replays identically. No retry-until-green.
- Free, fast, offline, so you can run it on every generation. No real account, no provisioning latency, no spend, no blast radius. Suitable for tight inner loops and CI on every candidate the model produces.
- API-call cost metering as a machine-gradeable guardrail. An AI has no
instinct for bill shock. Substrate prices each API call a run makes, and can gate
on the sum:
client.Deploy(ctx, tmpl, Intent{MaxCost: 1.0})returnsErrCostBudgetExceededwhen the deploy's metered cost exceeds the budget. It meters calls, not resource time — a running instance's hourly rate is not counted; a resource-time cost model is tracked in #1615. - Seedable failure paths, to verify the error handling the code claims to have. Generated code is full of retry/poll/wait logic for capacity errors, throttling, and terminal states. Substrate lets you seed exactly those outcomes on demand, so the unhappy paths are actually exercised — not just assumed.
AI generation is the motivating use case, not a prerequisite: Substrate is equally useful for human-written Terraform, CDK, CloudFormation, SDK, and CLI integration tests that want the same determinism, offline speed, and cost metering.
Substrate is a different tier from container emulators and real accounts, not a drop-in replacement. It trades workload-execution fidelity and breadth for determinism, replayability, and API-call cost metering — the fast inner-loop tier.
As of 2026-11. A cell with a number cites that project's own documentation, listed under Sources; the rest come from the comparison recorded in #1597. "Not documented" means the project's documentation says nothing either way. These projects evolve; treat this as positioning, not a current audit.
| Substrate | LocalStack | moto | AWS Emulator | Real AWS | |
|---|---|---|---|---|---|
| Access | Free, open source, no account | Auth token required; the free Hobby plan is non-commercial [1] | Free, open source | Free, open source, no account [4] | Account and spend |
| Any SDK/CLI over HTTP | ✅ (also in-process in Go) | ✅ | ✅ server mode [3] | ✅ (also embedded in the Rust SDK) [4] | ✅ |
| Replay of a recorded run | ✅ bodies recorded by default; replays under the recorded request IDs and clock | ❌ | Partial: the Recorder re-sends requests; no responses are kept or compared [3] | Not documented | ❌ |
| Same identifiers on a fresh run | ✅ seeded request IDs by default; clock pinning opt-in; not across concurrent requests | Not documented | ✅ /moto-api/seed [3] |
Not documented | ❌ |
| Simulated, controllable clock | ✅ | Not documented | ❌ wall clock | Not documented | ❌ |
| Time-travel state inspection | ✅ state before any event; step backward and forward | ❌ | ❌ | Not documented | ❌ |
| Seeded failure outcomes | ✅ seed endpoints and deterministic fault rules | Chaos API on the Enterprise plan; each rule fires with a set probability [2] | Partial | Not documented | ❌ |
| IAM policy evaluation | ✅ | Base plan and up | Partial | ❌, and one account only [4] | ✅ |
| API-call cost metering | ✅ per call; resource time is #1615 | ❌ | ❌ | Not documented | After the bill |
| Runs your workload code | ❌ (by design) | ✅ | ❌ | Not documented | ✅ |
LocalStack and moto cover more of AWS than Substrate does, and AWS Emulator is generated from AWS's own Smithy models and answers an operation it does not implement with HTTP 501 [4]; Substrate does not compete on breadth. Two newer emulators, Floci and kumo (Go, and usable in-process from a Go test), are not assessed here.
Sources
- [1] LocalStack's repository, archived by its owner on 2026-03-23, and its pricing page, where Hobby is "for hobbyists & other non-commercial usage".
- [2] LocalStack's Chaos API documentation.
- [3] moto's server mode and Recorder and deterministic identifiers documentation.
- [4] The AWS News Blog's launch post, 2026-11-11.
The one ❌ is deliberate: Substrate models what is observable through an AWS API call, not what software inside a resource does (see Scope & Philosophy). If you need to execute your Lambda's code or boot a real container, reach for LocalStack or a real account; if you need to test how your infrastructure code drives and reacts to the AWS API — fast, deterministically, and on every AI-generated candidate — that's Substrate.
Every AWS request is recorded as an immutable event, with its request and response bodies, over a simulated clock. A replay re-runs the events under their recorded request IDs and clock, so it reproduces the run — and a failing run replays as the same failure.
func TestCreateBuckets(t *testing.T) {
ts := emulator.StartTestServer(t) // records request and response bodies by default
createBuckets(t, ts.URL) // your code under test, pointed at ts.URL
// Replay the recorded run into a fresh sandbox, under the recorded request IDs and
// clock, and fail the test on any difference from what the live run answered.
ts.AssertReplay(t)
}Two fresh runs agree too. Every identifier substrate mints is derived from its
request's ID, and StartTestServer and the pytest plugin seed request IDs by default,
so the same calls in the same order mint the same IDs on every run. Pinning the clock
as well, so timestamps repeat, is opt-in: WithDeterministicRun(epoch),
@pytest.mark.substrate(deterministic=True), or substrate server --seed N --epoch T.
The documented exceptions are requests sent concurrently (they draw IDs in scheduling
order), the HTTP Date header, and a stream that spans a state reset, which replays
faithfully only between resets; see
Deterministic Runs.
Inspect the state a recorded run had before any of its events, or walk a replay backward and forward through it, to see where a sequence of API calls diverged from what you expected.
sb := ts.ReplaySandbox(t) // a replay of the server's stream, apart from its live state
events, err := ts.Store().GetStream(ctx, emulator.DefaultStreamID)
// The state before the last request ran: the event's Sequence names the point.
at, err := sb.StateAt(ctx, emulator.DefaultStreamID, events[len(events)-1].Sequence)
// at.State is the state snapshot; at.Differences is where replaying to it diverged.
// Or drive the replay engine: replay the stream, then walk back through it.
engine := sb.Engine()
results, err := engine.Replay(ctx, emulator.DefaultStreamID)
ev, err := engine.StepBackward(ctx) // back one event; ev is the next to run
err = engine.JumpToEvent(ctx, 1) // a stream position: before the second event
s3State, err := engine.InspectState(ctx, "s3") // one namespace's keys at this pointJumpToEvent takes a position in the stream (0 is before the first event);
JumpToSequence takes an Event.Sequence. Both snippets run as
emulator/readme_snippets_test.go. Outside Go, a
running server answers GET /v1/debug/events/{seq}/state, and
substrate debug state-at SEQ --stream S prints the same for a persisted event store.
A recorded run can also become a standalone regression test: GenerateTestFixture
embeds its events and replays them in process.
Each emulated request is priced from a per-operation table (with overrides,
discounts, and credits), recorded on its event, and summed per service and
operation. Intent{MaxCost} turns the sum into a gate:
result, err := client.Deploy(ctx, tmpl, emulator.Intent{MaxCost: 1.0})
if errors.Is(err, emulator.ErrCostBudgetExceeded) {
// The stack was deployed (result is set); its metered cost exceeded $1.
}This is API-call metering, not a monthly bill: a stack's cost is what its API calls
are priced at, so a large EC2 instance contributes its RunInstances call, not its
hourly rate. A resource-time cost model is tracked in
#1615.
Determinism doesn't mean every test sees the same result. Substrate defaults to
the nominal success path; a test seeds an alternate outcome — an
InsufficientInstanceCapacity on launch, a training job that comes back Failed
with a CapacityError, a specific query result — and the plugin returns it at
request time, fully reproducibly. The failure, capacity, and timing paths that
are rare or impossible to trigger against real AWS become trivial to test.
The primary way to use Substrate is as a drop-in AWS endpoint.
go install github.com/scttfrdmn/substrate/cmd/substrate@latestOr build from source / run with Docker:
git clone https://github.com/scttfrdmn/substrate && cd substrate
make build # produces ./bin/substrate
docker run -p 4566:4566 ghcr.io/scttfrdmn/substrate:latestsubstrate server
# Listening on :4566Configuration via substrate.yaml or environment variables (see
substrate.yaml.example).
AWS CLI
aws iam create-user --user-name alice \
--endpoint-url http://localhost:4566 --region us-east-1 --no-sign-requestOr set a profile in ~/.aws/config:
[profile substrate]
region = us-east-1
endpoint_url = http://localhost:4566Go SDK v2
cfg, _ := config.LoadDefaultConfig(context.TODO(),
config.WithRegion("us-east-1"),
config.WithBaseEndpoint("http://localhost:4566"),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("test", "test", "")),
)
client := iam.NewFromConfig(cfg)Python (boto3)
import boto3
client = boto3.client(
"iam", region_name="us-east-1",
endpoint_url="http://localhost:4566",
aws_access_key_id="test", aws_secret_access_key="test",
)Node.js (AWS SDK v3)
import { IAMClient } from "@aws-sdk/client-iam";
const client = new IAMClient({
region: "us-east-1",
endpoint: "http://localhost:4566",
credentials: { accessKeyId: "test", secretAccessKey: "test" },
});For Go code, the fastest path is StartTestServer, which spins up an in-process
server on a random port and registers a t.Cleanup to shut it down.
import "github.com/scttfrdmn/substrate/emulator"
func TestMyInfra(t *testing.T) {
ts := emulator.StartTestServer(t)
cfg, _ := config.LoadDefaultConfig(context.Background(),
config.WithRegion("us-east-1"),
config.WithBaseEndpoint(ts.URL),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("test", "test", "")),
)
// Use cfg with any AWS SDK v2 client...
}Or deploy a CloudFormation template and validate it entirely in-process, no HTTP
server required, via the in-process emulator.Client:
import "github.com/scttfrdmn/substrate/emulator"
store := emulator.NewEventStore(emulator.EventStoreConfig{Enabled: true, Backend: "memory"})
state := emulator.NewMemoryStateManager()
tc := emulator.NewTimeController(time.Now())
registry := emulator.NewPluginRegistry()
client := emulator.NewClient(registry, store, state, tc, logger)
// err wraps emulator.ErrCostBudgetExceeded if the metered cost exceeds MaxCost.
result, err := client.Deploy(ctx, cfnTemplate, emulator.Intent{MaxCost: 1.0})
session, _ := client.StartRecording(ctx, "my-test")
// ... run operations against the emulator ...
report, _ := client.StopRecording(ctx, session)
fmt.Printf("status=%s cost=$%.4f\n", report.PassFail, report.Cost.Total)The Go import path is
github.com/scttfrdmn/substrate/emulator. Installing the CLI (.../cmd/substrate@latest) is unaffected.
See examples/validation_workflow/main.go for a
complete runnable example.
Substrate's built-in service plugins span compute, storage, networking, databases, messaging, analytics, ML, security, and management. The coverage matrix lists every plugin and how many operations it routes; it is generated from the plugin registry, so it cannot drift.
- Compute & containers — EC2, Lambda, ECS, ECR, Batch, EKS-adjacent
- Storage & data — S3, EFS, FSx, DynamoDB, RDS, Redshift, ElastiCache, Timestream
- Networking — VPC/EC2, ELBv2, Route 53, CloudFront, API Gateway (REST & HTTP)
- Messaging & streaming — SQS, SNS, EventBridge, Kinesis, Firehose, MSK
- ML & analytics — SageMaker, Bedrock Runtime, Athena, Glue, EMR Serverless, OpenSearch, QuickSight, HealthOmics
- Security & identity — IAM, STS, KMS, Secrets Manager, ACM, Cognito, SSO, WAFv2, RAM
- Management & cost — CloudWatch (+ Logs), CloudTrail, Organizations, Budgets, Cost Explorer, Service Quotas, SSM, Health, the CodeSuite, Step Functions, Backup, Transfer
Many are also reachable through CloudFormation deployment. Each plugin has a page under
docs/reference/ with its per-operation detail. A running server
reports its plugins from the /ready endpoint (curl http://localhost:4566/ready).
- Cross-service IAM enforcement — policies are evaluated for IAM and STS; per-operation enforcement for other services is partial.
- Persistence — in-memory by default; SQLite available via
EventStoreConfig{Backend: "sqlite"}. - Authentication — SigV4 verification is opt-in (off by default for testing
ease); enable with
ServerOptions.VerifySignatures = true. - Workload internals are out of scope by design — Substrate models the API surface, not what runs inside a resource (see What is Substrate?).
Actively developed. See Releases for the current version and CHANGELOG.md for full history.
📖 Full documentation: scttfrdmn.github.io/substrate
- Getting Started — install, first test, 15-minute tutorial
- Service Reference — the coverage matrix, with a page per plugin under
docs/reference/ - Testing Guide —
StartTestServer, recording/replay, cost assertions - Endpoint Configuration — SDK and tool configuration
make test # run tests with the race detector
make lint # golangci-lint
make coverage # coverage report
make build # build the substrate binary
make e2e # end-to-end testsRequirements: Go 1.26+, golangci-lint.
Issues and pull requests welcome. All work is tracked in
GitHub Issues and organised into
Milestones. main is
protected — changes land via pull request.
Apache 2.0 — see LICENSE.