State Snapshots
State Snapshots
Section titled “State Snapshots”Save CloudMock’s state to a JSON file and restore it on startup. Teams can commit a cloudmock-state.json to version control so everyone starts with the same pre-configured resources.
Quick Start
Section titled “Quick Start”Export state
Section titled “Export state”# Create some resourcesaws --endpoint http://localhost:4566 s3 mb s3://my-bucketaws --endpoint http://localhost:4566 dynamodb create-table \ --table-name users \ --key-schema AttributeName=pk,KeyType=HASH \ --attribute-definitions AttributeName=pk,AttributeType=S \ --billing-mode PAY_PER_REQUEST
# Export to filecurl -X POST http://localhost:4599/api/state/export > cloudmock-state.jsonRestore state on startup
Section titled “Restore state on startup”cloudmock --state cloudmock-state.jsonAll resources are instantly available — no need to re-create them.
Auto-save on shutdown
Section titled “Auto-save on shutdown”cloudmock --state cloudmock-state.json --persistState is automatically saved when CloudMock receives SIGTERM (Ctrl+C). Next startup loads the saved state.
State File Format
Section titled “State File Format”{ "version": 1, "exported_at": "2026-04-02T20:00:00Z", "services": { "s3": { "buckets": [ { "name": "my-bucket", "objects": [ { "key": "config.json", "body_base64": "eyJrZXkiOiJ2YWx1ZSJ9", "content_type": "application/json" } ] } ] }, "dynamodb": { "tables": [ { "name": "users", "key_schema": [{ "AttributeName": "pk", "KeyType": "HASH" }], "attribute_definitions": [{ "AttributeName": "pk", "AttributeType": "S" }], "billing_mode": "PAY_PER_REQUEST", "items": [ { "pk": { "S": "user-1" }, "name": { "S": "Alice" } } ] } ] } }}Supported Services
Section titled “Supported Services”| Service | What’s saved | What’s not saved |
|---|---|---|
| S3 | Buckets, objects (key + body + content type) | Multipart uploads in progress |
| DynamoDB | Tables (schema, GSIs, LSIs), items | Streams, TTL config |
| SQS | Queues, attributes | In-flight messages, DLQ config |
| SNS | Topics, subscriptions | Pending confirmations |
| Lambda | Function configs (name, runtime, handler, env) | Invocation logs |
| IAM | Users, roles, policies, attachments | Access keys |
| CloudWatch Logs | Log groups | Log events |
| Route53 | Hosted zones | Records |
Admin API
Section titled “Admin API”| Endpoint | Method | Description |
|---|---|---|
/api/state/export | POST | Export current state as JSON |
/api/state/import | POST | Import state from JSON body |
/api/state/reset | POST | Clear all service state |
CI Usage
Section titled “CI Usage”Commit cloudmock-state.json to your repo and load it in CI to skip setup boilerplate:
# GitHub Actions- run: npx cloudmock --state cloudmock-state.json &- run: sleep 2- run: npm testDocker
Section titled “Docker”docker run -v ./cloudmock-state.json:/state.json \ -p 4566:4566 ghcr.io/viridian-inc/cloudmock:latest \ --state /state.jsonGo SDK (In-Process)
Section titled “Go SDK (In-Process)”cm := sdk.New(sdk.WithStateFile("cloudmock-state.json"))defer cm.Close()// All resources from the state file are available immediately