← Offstack All Offstack Docs Topic & How-To Guides v15.0.0 · ~22 KB

Embedding Offstack in Your App

Wire unmodified apps, containers, CI workflows, health probes, offline cost diffing, and code-signed Windows builds around a local Offstack instance.

This is the manual for running Offstack as part of something else — a test harness, a developer workspace, a CI job, a product that ships it — rather than as a standalone simulator you start by hand.

Offstack is an API, not a library. Its surface is AWS's wire protocol: the moment it is running, any AWS SDK pointed at the right port talks to it with no code change beyond the endpoint. Embedding therefore means launching and supervising a process, and this document is chiefly about that process contract — how to start it, where its ports are, which files it needs, how to know it is up, and how to stop it without orphaning workers.

Status note (v15.0.0): Originally written against the 2026-11-17 tree; updated for v15.0.0 (--unified-port 4566, offstack exec, /healthz + /readyz + /metrics, 96 AWS services, 15 clouds, 12 RDBMS backends, 8 wire bridges, --no-apigw-data-plane, and offstack.cmd nuitka_module installs). Where an original 2026-11-17 measurement is cited, it is labelled by date.


1. What "embedding" means here

There are two things you might mean, and they lead to different instructions:

You want your application's AWS calls to land on Offstack. This is the common case. You do not import anything; you start the process and point the SDK at it. See §2–§5.

You want Offstack inside your own process. There is no supported entry point for that today, and it is not a small gap: every service is its own HTTP server on its own thread, start.py owns their lifecycle, and several of them (RDS, the Lambda worker pool) spawn child processes that must be owned by whoever started them. Attempting it by importing the service modules directly gets you the servers without the lifecycle, which is the part that matters. If you need this, say so — it is a real feature to design, not a wiring exercise.


2. Launching it

From source

python start.py [flags]

From an installed / packaged build

# Installed Enterprise build (Windows VibeInstaller nuitka_module: offstack.cmd launcher)
offstack --unified-port 4566 [flags]

# Standalone packaged binary (historical onefile / Linux release tarball)
offstack.exe [flags]         # or /opt/offstack/offstack on Linux

# Zero-code drop-in runner (spawns/connects gateway + sets AWS_ENDPOINT_URL & CA env for child command)
offstack exec -- pytest tests/

The installed / packaged build accepts the same flags and resolves sidecar files relative to OFFSTACK_ROOT / TOOLKIT_APP_ROOT / install dir (§4). Build and verification procedure is in docs/PACKAGING.md.

What "started" means

start.py starts every service, waits for each to accept a TCP connection, and only then prints a banner:

============================================================
  Offstack
============================================================
  DynamoDB   : http://localhost:13000
  S3         : http://localhost:13001
  ...
  Mode       : cold-lambda | in-memory
============================================================

  Press Ctrl+C to stop.

The banner is the readiness signal, and its absence is the failure signal. A service that never became reachable makes start.py exit non-zero before printing anything, so:

(usually a port already in use). The log names which.

This is deliberate and is the contract STARTUP_CONTRACT.md records: before 2026-11-10 the launcher printed a warning and continued to the banner anyway, so a half-boot and a healthy boot were identical bytes on stdout to every consumer keying on it.

Do not wait a fixed number of seconds and assume it is up. Wait for the banner on stdout, or poll the ports. Both are reliable; a sleep is not.


3. Ports and Profiles

In v15.0.0, a full boot starts 96 AWS services (plus optional 14 non-AWS cloud gateways :4671 / :4690–4702 via --cloud and 8 data/SQL wire bridges :4703–4710 via --bridges). For most embedded and CI harnesses:

If you connect directly to per-service ports instead of --unified-port, each service also binds its own port (core defaults below; full 96-service, multi-cloud, and wire-bridge port tables live in docs/USER_MANUAL.md):

ServiceFlagDefault
DynamoDB--dynamodb-port13160
S3--s3-port13161
API Gateway (Lambda proxy)--lambda-port13000
STS--sts-port14592
SSM--ssm-port4593
Secrets Manager--secretsmanager-port4594
Lambda API (control plane + Invoke)--lambda-api-port4595
SQS--sqs-port4596
CloudWatch Logs--logs-port4597
CloudWatch metrics--cloudwatch-port4598
Cognito--cognito-port4599
EventBridge--events-port4600
SNS--sns-port4601
IAM--iam-port4602
DynamoDB Streams--dynamodbstreams-port4603
CloudFormation--cloudformation-port4604
Kinesis--kinesis-port4605
Step Functions--stepfunctions-port4606
RDS--rds-port4607
RDS Data--rds-data-port4608
EventBridge Schemas--schemas-port4609
API Gateway control plane--apigateway-port4610
API Gateway v2 control plane--apigatewayv2-port4611
EventBridge Scheduler--scheduler-port4612
EventBridge Pipes--pipes-port4613
SES (v1 query API)--ses-port4614
SESv2 (rest-json)--sesv2-port4615
KMS--kms-port4616
ACM (import path + local CA)--acm-port4617
Cognito Identity--cognito-identity-port4618
X-Ray (intake)--xray-port4619
Timestream write--timestream-write-port4620
Timestream query--timestream-query-port4621
S3 Tables--s3tables-port4622
Route53 (private zones)--route53-port4623
CodeCommit (real git)--codecommit-port4624
ElastiCache (fakeredis data)--elasticache-port4625
MemoryDB (fakeredis data)--memorydb-port4626

Two of these defaults — DynamoDB and S3 — are read from a fleet port registry when one is present on the machine, so they may differ from the table. Read the banner, or pass explicit ports; never hard-code 13160/13161 assuming they are universal.

Ephemeral ports

Passing 0 for any port asks the OS for a free one. This is how the test harness runs, and it is what you want in CI or whenever two copies may run at once:

python start.py --dynamodb-port 0 --s3-port 0 ... # etc.

The banner then shows the ports actually bound, not the 0 you passed. A supervisor must parse them from the banner (or from an explicit fixed-port flag it chose); the requested value is not usable from outside.


3a. ACM: issuing against a local CA

RequestCertificate works, but not the way AWS does it. AWS asks a public CA to issue; no client anywhere will trust a certificate minted by a laptop. So Offstack runs a local CA and says so. This is the honest boundary, not a limitation to work around:

Status: ISSUED. There is no DNS/email validation loop — both ends are the same machine, so simulating one would be theatre.

AWS needs no equivalent because its CA is already in every trust store.

To make TLS actually work, fetch the CA once and point your client at it:

import json, urllib.request

port = 4617                      # ACM's port from the startup banner
request = urllib.request.Request(
    f"http://127.0.0.1:{port}/",
    data=b"{}",
    headers={"X-Amz-Target":
             "CertificateManager.GetLocalCaCertificate",
             "Content-Type": "application/x-amz-json-1.1"},
    method="POST")
with urllib.request.urlopen(request) as response:
    ca_pem = json.loads(response.read())["CaCertificate"]
open("ca.pem", "w", encoding="ascii").write(ca_pem)

(GetLocalCaCertificate is not in botocore's ACM model — AWS has no such operation — so it goes over raw JSON rather than through boto3.client("acm").)

Then trust it for the process:

export SSL_CERT_FILE=/path/to/ca.pem         # POSIX
set SSL_CERT_FILE=C:\path\to\ca.pem          # cmd

openssl s_client -connect host:port -CAfile ca.pem verifies against it the same way. A client that trusts only the public roots will reject these certificates — correctly, and by design.

The CA key lives beside the state database (<state dir>/acm-ca/), is unencrypted (an emulator cannot prompt for a passphrase), and must never be installed into a machine-wide trust store. With :memory: state — the test default — the CA is per-process under the OS temp directory, so two runs do not share a signer and no key is written into the source tree. See acm/local_ca.py for the full rationale and for what moto and MiniStack do instead (a twelve-byte fake, and a real certificate with a forged issuer that fails openssl verify).

4. Files it reads

Offstack is started in some directory and reads several files from it. Which one matters for the packaged binary, which resolves them relative to itself.

FlagDefaultWhat it isRead when
--s3-data-dir./s3_dataWhere S3 object bytes livealways (created if absent)
--lambda-config<install>/lambda_routes.jsonRoute table for the API Gateway proxy fallbackat boot, and on change
--env-file<install>/env.jsonEnvironment for Lambda handlersat boot
--stack-file./stacks.jsonCloudFormation stack stateat boot
--state-file./offstack_state.dbThe shared service databaseonly with --persist
—./table_schemas/Table schemas, if presentat boot

Writable working directory. S3 data, the state file and the CloudFormation stack file are written under the current directory by default. A process that runs in a read-only or shared directory will fail, and will do so with a bind or open error rather than a message about the working directory. Give the embedder its own directory, or point --s3-data-dir and --stack-file somewhere writable.

API Gateway data plane & lambda_routes.json

When lambda is enabled, the API Gateway :13000 data plane starts automatically even if lambda_routes.json is absent (serving routes created via the API Gateway v1/v2 control plane --apigateway-port / --apigatewayv2-port). Pass --no-apigw-data-plane if you want to skip binding --lambda-port completely.

--lambda-config (lambda_routes.json) acts as a fallback route table, consulted only when the control plane has no route to deploy. An earlier broken fallback bug from 2026-11-17 is fixed and verified by scripts/verify_packaged_lambda.py. If you rely on file-based fallback routes with no control-plane API calls, verify that case explicitly in your install layout.

env.json

The environment handed to every Lambda handler. A key here reaches the handler as an environment variable. Endpoint variables your handler needs are injected by Offstack already (§5), so env.json is for your configuration only.


5. Pointing your application at it

Start Offstack with --unified-port 4566 (or add --tls for HTTPS on :4567) and set one endpoint variable:

export AWS_ENDPOINT_URL=http://127.0.0.1:4566
export AWS_REGION=us-east-1
export AWS_ACCESS_KEY_ID=local          # any non-empty value
export AWS_SECRET_ACCESS_KEY=local

Or wrap your test/app process directly with zero manual env setup:

offstack exec --tls -- pytest tests/

Option B: Direct per-service ports (AWS_ENDPOINT_URL_<SERVICE>)

If you do not use --unified-port and instead talk directly to per-service ports, there is no catch-all across distinct ports: setting AWS_ENDPOINT_URL alone sends every service to whichever single port you named, and every other service answers with a protocol error (measured 2026-11-17 when pointed at DynamoDB's direct port):

dynamodb  → OK
s3        → 400 Bad Request
sqs       → ValidationException
sns       → ResponseParserError
logs      → ValidationException

In direct-port mode, each service needs its own variable:

export AWS_REGION=us-east-1
export AWS_ACCESS_KEY_ID=local          # any non-empty value
export AWS_SECRET_ACCESS_KEY=local
export AWS_ENDPOINT_URL_DYNAMODB=http://127.0.0.1:13160
export AWS_ENDPOINT_URL_S3=http://127.0.0.1:13161
export AWS_ENDPOINT_URL_SQS=http://127.0.0.1:4596
# ... one per service you use

The variable name is not always the client id. botocore builds it from the service's hyphenized service id, which for most services is the client name but for several is not. The ones that catch people, all verified 2026-11-17 by setting the variable and watching where the call landed:

ClientCorrect variableWrong name that silently hits real AWS
boto3.client("events")AWS_ENDPOINT_URL_EVENTBRIDGE..._EVENTS
boto3.client("logs")AWS_ENDPOINT_URL_CLOUDWATCH_LOGS..._LOGS
boto3.client("cognito-idp")AWS_ENDPOINT_URL_COGNITO_IDENTITY_PROVIDER..._COGNITO_IDP
boto3.client("dynamodbstreams")AWS_ENDPOINT_URL_DYNAMODB_STREAMS..._DYNAMODBSTREAMS
boto3.client("stepfunctions")AWS_ENDPOINT_URL_SFN..._STEPFUNCTIONS
boto3.client("secretsmanager")AWS_ENDPOINT_URL_SECRETS_MANAGER..._SECRETSMANAGER
boto3.client("rds-data")AWS_ENDPOINT_URL_RDS_DATA..._RDSDATA
boto3.client("apigateway")AWS_ENDPOINT_URL_API_GATEWAY..._APIGATEWAY

A wrong name is not an error — the client goes to real AWS with the credentials in your environment. Measured directly: with only AWS_ENDPOINT_URL_STEPFUNCTIONS set, list_state_machines answered UnrecognizedClientException (i.e. it reached AWS and was rejected); AWS_ENDPOINT_URL_SFN answered from Offstack. So a typo here does not fail loudly — it silently spends on, and depends on, a real account. If a call suddenly needs credentials for an account you did not expect, check the variable name first.

Inside a Lambda handler running under Offstack these variables are already set for you; a handler needs no endpoint configuration at all.

Or pass the endpoint per client, which avoids the question entirely:

import boto3
kw = dict(endpoint_url="http://127.0.0.1:13160", region_name="us-east-1",
          aws_access_key_id="local", aws_secret_access_key="local")
dynamodb = boto3.client("dynamodb", **kw)

6. Lifecycle

Starting

Start the process, wait for the banner or poll the ports (§2). The process runs until told to stop.

Readiness

When running with --unified-port (default 4566), Offstack serves built-in observability endpoints alongside API traffic:

When polling per-service ports without --unified-port, readiness is "the port accepts a TCP connection" — which is also what start.py waits for before printing the startup banner (Press Ctrl+C to stop.).

Stopping

Send SIGINT or SIGTERM, or Ctrl-C in a terminal. start.py catches both, then shuts every service down in order, including the Lambda invoker, which kills the handler worker processes it owns.

On Windows, do not TerminateProcess the simulator. A worker that is kill()ed rather than shut down is orphaned, and orphaned Node Lambda workers are not free: a single abandoned test session left 52 of them holding 2.2 GB, which then starved later runs. This is why the invoker registers an atexit hook and why the packaged binary is two processes (bootstrapper + payload) — taskkill /T on the bootstrapper does not always reach the payload's workers.

If you must kill it hard, kill the whole process tree by PID, and verify no lambda_cold_worker processes remain.

Persistence

By default every store is in memory: stopping the simulator discards all state. For state that survives a restart:

python start.py --persist                       # ./offstack_state.db
python start.py --persist --state-file /path/to/state.db
OFFSTACK_DATABASE_URL="postgresql+psycopg://user:pass@host/db" \
  python start.py --persist

S3 object bytes are on disk in --s3-data-dir regardless; it is the metadata that persistence covers. DATABASES.md covers the SQL backends.


7. The cost simulator & Inspector UI

Offstack can estimate what the traffic it served would cost at AWS list prices and inspect live resource state through the 24-tab offline /_offstack/ Inspector UI (14 core + 10 enterprise tabs when running --unified-port, plus offstack cost snapshot|diff|compare). Metering is off by default and costs one attribute read per request when off.

OFFSTACK_METERING=1 OFFSTACK_DEBUG=1 python start.py --unified-port 4566 ...
offstack cost snapshot --url http://127.0.0.1:4566 --out baseline.json
offstack cost diff baseline.json head.json --fail-over-usd 25

Raw snapshots are served on /_offstack/api/cost (--unified-port) and debug-gated /_ui/cost on S3 (OFFSTACK_DEBUG=1). Pricing happens in the client/CLI using cached AWS Price List data so live request paths never block on the network.

What it can and cannot price, and why, is in COST_REPORT.md. Two properties worth knowing as an embedder:

partial.** An operation it saw but could not price is a visible row, never a silent zero.

that is not the same as free — it means traffic to it is absent from the total. If you embed Offstack in a long-lived process, this is the line to check before trusting a figure.

Storage (S3 and DynamoDB GB-months) is priced from bytes held right now, as one month's rent at today's occupancy, not as a charge accrued since boot.


8. Known gaps

Honest list (updated for v15.0.0):


9. A worked example

A CI job that runs one test file against a throwaway simulator. This is the script that was run to verify this section; it passes.

#!/usr/bin/env bash
set -euo pipefail
work="$(mktemp -d)"
pid=""
trap '[ -n "$pid" ] && kill -TERM "$pid" 2>/dev/null || true' EXIT

python start.py \
  --dynamodb-port 0 --s3-port 0 --sqs-port 0 \
  --s3-data-dir "$work/s3_data" \
  --stack-file "$work/stacks.json" \
  > "$work/sim.log" 2>&1 &
pid=$!

# Wait for the banner, not for a number of seconds.
for _ in $(seq 1 120); do
  grep -q "Press Ctrl+C to stop" "$work/sim.log" && break
  sleep 0.5
done
grep -q "Press Ctrl+C to stop" "$work/sim.log" || {
  echo "simulator did not start:"; cat "$work/sim.log"; exit 1; }

# Take the ports the banner reports (the 0s above became ephemeral ones).
# The banner colours the URL with ANSI escapes, so strip them first. A shell
# variable holding a literal ESC is the portable way; `sed 's/\x1b.../'` is not.
ESC=$(printf '\033')
ddb_port=$(sed "s/${ESC}\[[0-9;]*m//g" "$work/sim.log" \
  | sed -n 's/^  DynamoDB *: http:\/\/localhost:\([0-9]*\).*/\1/p' | head -1)
s3_port=$(sed "s/${ESC}\[[0-9;]*m//g" "$work/sim.log" \
  | sed -n 's/^  S3 *: http:\/\/localhost:\([0-9]*\).*/\1/p' | head -1)

env AWS_ENDPOINT_URL_DYNAMODB="http://127.0.0.1:$ddb_port" \
    AWS_ENDPOINT_URL_S3="http://127.0.0.1:$s3_port" \
    AWS_REGION=us-east-1 AWS_ACCESS_KEY_ID=local AWS_SECRET_ACCESS_KEY=local \
  pytest tests/your_suite.py

Note the three things this does that a naive wrapper gets wrong: it waits for the banner rather than sleeping, it takes the ports from the banner rather than assuming the 0s it passed were kept, and it strips the banner's ANSI colour codes before parsing — the URL is wrapped in escape sequences, so a plain sed match on : http will not cross them.


Want a live walkthrough or evaluation setup for Offstack? Message George Vranjesevic or reach out at george@developmentsnapshot.com.