Running Wasm Modules on AWS Lambda with Spin

Cloud Computing
Date:November 22, 2026
Topic:
Running Wasm Modules on AWS Lambda with Spin
⏱ 3 min read

Your Lambda cold starts are measured in milliseconds. Your container startup is measured in seconds. That gap is where WebAssembly wins, and Spin makes it dead simple to run Wasm modules on AWS Lambda without managing a custom runtime or wrestling with the provided.al2 image.

Why Wasm on Lambda Changes the Economics

Traditional Lambda functions initialize a full microVM. Even with SnapStart for Java or provisioned concurrency, you pay for memory allocated during init. A Wasm module spins up in microseconds. Spin compiles your Rust, Go, or TypeScript code to a `.wasm` component that executes inside the Wasmtime runtime, which Fermyon and AWS optimized for Lambda's Firecracker microVMs. The result: sub-millisecond cold starts at 128 MB memory, slashing both latency and cost.

toml
[component.my-api]
source = "target/wasm32-wasip1/release/my-api.wasm"
[component.my-api.trigger]
route = "/..."
[component.my-api.build]
command = "cargo build --target wasm32-wasip1 --release"

Bootstrap a Spin App for Lambda

Install the Spin CLI and the AWS plugin. The plugin handles the heavy lifting: it packages the Wasm module, the Spin manifest, and a tiny bootstrap binary into a Lambda-compatible ZIP.

bash
spin new http-rust my-api
cd my-api
spin plugins install aws
spin aws deploy --region us-east-1
💡
TipUse `spin build --up` to test locally against the same Wasmtime runtime Lambda uses. No Docker required.

The Runtime Adapter Pattern

Lambda expects a handler with the signature `fn(event, context) -> Result`. Spin's `spin-aws-lambda` adapter translates the Lambda event (API Gateway, SQS, EventBridge) into a standard HTTP request your Wasm component understands. Your code stays pure HTTP; the adapter handles the translation layer.

rust
use spin_sdk::http::{Request, Response};

#[spin_sdk::http_component]
fn handle(req: Request) -> anyhow::Result<Response> {
    Ok(http::Response::builder()
        .status(200)
        .body("Hello from Wasm on Lambda".into())?)
}

Cold Start Benchmarks: Container vs Wasm

RuntimeMemoryCold Start (p50)Cold Start (p99)Init Duration Billed
Node.js 20 (container)256 MB245 ms1.2 sYes
Rust (provided.al2)128 MB85 ms310 msYes
Spin Wasm (Rust)128 MB0.8 ms4 msNo
"

WebAssembly on Lambda isn't just faster startup—it's a fundamentally different cost model. You pay for compute, not initialization.

— Michael Yuan, Wasm on Serverless Advocate

Handling State and Secrets

Wasm modules are ephemeral and stateless by design. For persistent state, bind to AWS services via the Spin SDK: `spin-sdk::key_value` for DynamoDB, `spin-sdk::sqlite` for a local SQLite database that persists across invocations in the same microVM, or `spin-sdk::redis` for ElastiCache. Secrets live in AWS Secrets Manager; the `spin aws deploy` command injects them as environment variables at deploy time, not build time.

⚠️
WarningDon't bundle secrets in the Wasm module. The `.wasm` file is readable by anyone with deployment access. Use the `spin_secrets` manifest section to reference ARNs.

Deploy Pipeline: Git Push to Live Endpoint

Wire this into GitHub Actions. The workflow builds the Wasm target, runs `spin aws deploy`, and updates the Lambda alias. Zero-downtime deploys are native because Lambda shifts traffic atomically.

yaml
name: Deploy to Lambda
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: fermyon/spin-action@v2
      - run: spin aws deploy --region ${{ secrets.AWS_REGION }}
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

✦

Your Next Step

Pick one high-latency Lambda function—maybe an API Gateway authorizer or a webhook validator. Rewrite it in Rust, compile to `wasm32-wasip1`, and deploy with `spin aws deploy`. Measure the p99 cold start before and after. You'll see the difference in the first 100 invocations. Then migrate the rest of your latency-sensitive paths. The runtime is stable, the tooling is mature, and the cost savings are immediate.

Share𝕏 Twitterin LinkedInin Whatsapp