This repository contains examples demonstrating how to use the Namespace SDK across different programming languages.
examples/
├── go/ # Go SDK examples
├── typescript/ # TypeScript SDK examples
└── README.md # This file
The Go examples are located in the go/ directory. Each example demonstrates different aspects of the Namespace SDK:
| Example | Description |
|---|---|
| build | Building Docker images using BuildKit with authentication and secrets management |
| createinstance | Creating compute instances with specific configurations and running containers |
| createpartnerinstance | AWS identity federation with Namespace and creating instances with federated credentials |
| ensuretenant | Creating and managing tenants using AWS federation for identity management |
| buildandrun | Complete workflow: build image, create instance, run service, and connect via gRPC |
| macrun | Building and running Go applications on macOS/ARM64 instances |
| sidecar | Advanced instance configuration with sidecar containers and SSH access |
Prerequisites
- Go 1.21 or later
- Namespace authentication credentials
- For AWS federation examples: AWS credentials with appropriate permissions
Common SDK Patterns
- Authentication: Token loading from workstations (
auth.LoadUserToken()) or instances (auth.LoadWorkloadToken()) - Compute API: Creating instances, waiting for readiness, describing instances
- Builds API: Building images with BuildKit, pushing to registry
- IAM API: Tenant creation and management with external account federation
- gRPC Communication: Client-server communication with TLS
Demonstrates using the Namespace Builds SDK with BuildKit to build Docker images from Dockerfiles.
Shows how to create compute instances with specific CPU/memory/architecture configurations and run containers.
Demonstrates AWS identity federation with Namespace and creating instances with federated credentials.
Shows how to create and manage tenants using AWS federation for identity management.
Complete end-to-end example: build a Docker image, create an instance, run a gRPC service, and connect to it.
Demonstrates building Go binaries for macOS/ARM64 and running them on Apple Silicon instances.
Advanced example showing instance configuration with sidecar containers, volume mounting, and SSH access.
The TypeScript examples are located in the typescript/ directory. The API is defined using Buf platform and uses TypeScript bindings generated by it. The underlying protocol is based on HTTP and uses text JSON encoding.
| Example | Description |
|---|---|
| kubernetes-demo | Create an ephemeral Kubernetes cluster and obtain kubeconfig |
| containers-demo | Create compute instances with containers and stream logs |
| iam-demo | Authenticate with Namespace using OpenID Connect and create tenants |
| macos-app-demo | Run applications on macOS/ARM64 instances with pre-start hooks |
-
Prerequisites
- Node.js 18 or later
- Namespace authentication credentials
-
Install Dependencies
cd typescript npm install -
Authentication
The examples require a tenant token, which can be obtained in two ways:
-
Using Namespace CLI (easiest for development):
curl -fsSL https://get.namespace.so/cloud/install.sh | sh nsc loginThe token will be read from
~/Library/Application Support/ns/token.json -
Using IAM API (for programmatic access): Set up AWS Workload Federation with Namespace using OpenID Connect and use the
iam-demoexample to obtain a tenant token
-
-
Common SDK Patterns
- Compute API: Creating instances, waiting for readiness, streaming logs
- IAM API: Tenant creation with OpenID Connect federation
- Kubernetes: Creating ephemeral clusters and obtaining kubeconfig
- Observability: Streaming instance logs in real-time
Creates an ephemeral Kubernetes cluster with ingress manager, waits for initialization, and downloads kubeconfig.
Demonstrates creating compute instances with container workloads and streaming logs from the observability API.
Shows how to authenticate with Namespace using OpenID Connect tokens, create tenants programmatically, and obtain tenant tokens. Requires setting up AWS Workload Federation with an OIDC issuer.
Runs applications on macOS/ARM64 instances with custom environment variables, pre-start hooks, and log collection.
For more information about the Namespace SDK and APIs, please visit:
Contributions are welcome! Please feel free to submit issues or pull requests.
See LICENSE file for details.