AI & Agents

How to Deploy OpenClaw on AWS Lambda for Serverless AI Agents

Running OpenClaw on AWS Lambda eliminates the fixed monthly cost of a dedicated server while keeping your AI agent available on demand. This guide walks through three serverless deployment paths on AWS, from Lambda Containers targeting roughly $1/month to Bedrock AgentCore for production multi-user setups, with CDK templates, cost math, and session persistence patterns for each.

Fastio Editorial Team 10 min read
AI agent architecture diagram showing serverless deployment patterns

Why Serverless Makes Sense for OpenClaw

Most OpenClaw deployment guides start with a VPS or Docker container. That works, but it means you are paying for compute 24/7 even when nobody is talking to the agent. For personal projects and small teams, a $5-20/month server sits idle the vast majority of the time.

Serverless flips that model. AWS Lambda charges per invocation and per millisecond of compute. If your agent handles 100 requests a day, you pay for those 100 requests and nothing else. During off-hours, your bill is effectively zero.

The tradeoff is cold starts. Lambda needs to spin up a container the first time it handles a request after a period of inactivity. For OpenClaw running as a Lambda Container image, the serverless-openclaw community project measured a cold start of about 1.35 seconds, with warm responses dropping to 0.12 seconds. That is fast enough for chat-based interactions where users expect a brief thinking delay anyway.

AWS offers several serverless paths for OpenClaw, each suited to different scales:

  • Lambda Containers: Package OpenClaw as a container image, run it directly on Lambda. Best for personal use and small teams targeting minimal cost.
  • Bedrock AgentCore: AWS-managed serverless runtime with per-user isolation via Firecracker microVMs. Built for production multi-user deployments with built-in guardrails.
  • Fargate Spot: Container orchestration without managing servers. Sits between Lambda and full ECS/EKS, useful as a fallback for long-running tasks that exceed Lambda's timeout.

The rest of this guide covers each option with enough detail to pick the right one and deploy it.

How Do Lambda, AgentCore, and Fargate Compare?

Before diving into setup, here is how the three main serverless approaches compare across the dimensions that matter most for an AI agent workload.

Lambda Containers

  • Cold start: ~1.35s
  • Warm response: ~0.12s
  • Cost at 100 requests/month: ~$0.01
  • Session persistence: S3 with DynamoDB concurrency control
  • Multi-user isolation: None (single tenant)
  • Infrastructure: CDK (TypeScript), single-command deploy
  • Best for: Personal agents, side projects, dev/test environments

Bedrock AgentCore

  • Cold start: 5-15s (lightweight agent), 1-2 minutes (full OpenClaw)
  • Warm response: A few seconds within an active session
  • Cost at scale: Pay-per-use with per-user Firecracker microVMs
  • Session persistence: S3 workspace sync built in
  • Multi-user isolation: Per-user containers with session-scoped IAM credentials
  • Infrastructure: CDK with 8 stacks, automated deploy script
  • Best for: Production multi-user bots (Telegram, Slack), teams needing guardrails and audit trails

Fargate Spot

  • Cold start: Longer (container pull + startup)
  • Cost at low volume: ~$0.27-1.11/month depending on free tier
  • Session persistence: Managed by the application
  • Multi-user isolation: Task-level isolation
  • Infrastructure: Part of the serverless-openclaw CDK stack as a fallback
  • Best for: Long-running agent tasks that exceed Lambda's 15-minute timeout

For most developers starting out, Lambda Containers offer the lowest cost and simplest path. If you need to serve multiple users through Telegram or Slack with proper isolation and content filtering, Bedrock AgentCore is the production-grade choice.

Diagram showing serverless architecture options for AI agent deployment

Deploying OpenClaw with Lambda Containers

The serverless-openclaw project packages OpenClaw as a Lambda Container image with a supporting cast of AWS services. The target is roughly $1/month for personal use, and the entire stack deploys with a single CDK command.

Architecture

The stack uses API Gateway for WebSocket and REST endpoints, Lambda Container images as the primary compute layer, DynamoDB (on-demand mode) for conversation history, and S3 for file storage and session persistence. A React SPA served through CloudFront provides the web chat interface, and Cognito handles JWT authentication.

The key design choice is using API Gateway instead of an Application Load Balancer. ALBs carry a fixed cost of $18-25/month, which defeats the purpose of a serverless deployment. API Gateway charges per request and per connection-minute, keeping costs proportional to actual usage.

Session Persistence with S3

Lambda functions are stateless by design, which creates a challenge for OpenClaw since it maintains conversation context and working files across interactions. The serverless-openclaw approach solves this by persisting session data to S3 after each invocation and loading it back on the next request. DynamoDB provides concurrency control to prevent race conditions when multiple requests arrive close together.

This pattern works well for chat-style interactions where requests are sequential. For workflows where an agent might receive parallel automation hooks events, the DynamoDB locking prevents data corruption at the cost of serializing those requests.

Pre-Warming (Optional)

If the 1.35-second cold start bothers you, EventBridge can schedule periodic warm-up invocations. Running a pre-warm schedule during weekday business hours adds roughly $0.07/month using Spot pricing. This eliminates cold starts entirely during the hours when you actually use the agent.

Deployment

The project uses AWS CDK with TypeScript and is organized as an npm workspaces monorepo. The setup process follows standard CDK conventions: install dependencies, configure environment variables, build, and deploy.

The repository includes 233 unit tests and 35 end-to-end tests, which is worth running before deploying to catch configuration issues early.

One important caveat: the project carries an alpha status warning. It has not been fully tested in production environments, and since it makes LLM API calls, costs can spike unexpectedly if you do not set budget alarms. Treat it as a solid starting point for personal use, not a turnkey production system.

Fastio features

Persist your serverless agent's output where your team can use it

generous storage workspace with MCP access, auto-indexing, and ownership transfer. No credit card, no trial expiration.

Deploying with Bedrock AgentCore for Multi-User Production

When you need to serve multiple users through messaging platforms like Telegram and Slack, Bedrock AgentCore provides a production-grade serverless runtime with per-user isolation.

Architecture

The aws-samples reference implementation deploys 8 CDK stacks covering networking, security, guardrails, the AgentCore runtime, automation hooks routing, observability, token monitoring, and scheduled tasks. Each user gets their own Firecracker microVM with session-scoped STS credentials, preventing one user's agent from accessing another's data.

The automation hooks flow works asynchronously: a Lambda function receives incoming messages from Telegram or Slack, stores them in DynamoDB, and the AgentCore backend processes them. This async pattern handles serverless cold starts gracefully because the user sees a "thinking" indicator in their chat app while the agent spins up, rather than a timeout error.

Built-In Guardrails

Bedrock Guardrails provide content filtering, PII redaction, and topic denial out of the box. The reference implementation includes 62 adversarial test cases and achieves roughly a 93% pass rate with guardrails enabled, compared to about 77% without them. Guardrails add approximately $0.75 per 1,000 text units on top of model inference costs.

Cost Controls

The CDK configuration includes sensible defaults for cost management:

  • Daily token budget alarm at 1,000,000 tokens
  • Daily cost budget alarm at $5
  • Session idle timeout at 30 minutes (configurable)
  • Maximum session lifetime of 8 hours
  • Registration-gated access (closed by default)

These controls matter because a misconfigured agent can burn through API credits quickly. The token monitoring stack uses a single-table DynamoDB design with four Global Secondary Indexes to track usage patterns without adding significant cost.

Supported Models

The default model is Anthropic Claude Sonnet 4.6 via cross-region inference profiles that automatically route to available regions. You can configure a separate, cheaper model for sub-agent tasks. The system supports multimodal messaging, handling JPEG, PNG, GIF, and WebP images up to 3.75 MB.

Deployment

Prerequisites include Python 3.11+, Node.js 18+, Docker, AWS CDK, and the AgentCore Toolkit. The automated deploy script runs in three phases and handles the full stack. After deployment, you configure your Telegram or Slack automation hooks and add users to the allowlist.

Audit trail and monitoring dashboard for production AI agent deployment

Persisting Agent Output with External Storage

Both serverless approaches write session data and working files to S3. That works for the agent's internal state, but it does not solve the broader problem of making agent output accessible to humans.

When an OpenClaw agent produces a report, generates a document, or collects data, someone on your team eventually needs to review, approve, or share that output. S3 is not designed for human collaboration. It lacks previews, search, commenting, and access controls that non-technical team members can use without AWS Console access.

This is where a workspace layer fits into the architecture. You can configure your agent to upload finished output to a shared workspace where team members access it through a browser, search it with natural language, and hand it off to clients.

Local storage on the Lambda container itself is ephemeral and disappears after each invocation. S3 provides durable storage but requires AWS credentials and tooling to access. Google Drive and Dropbox work for individual files but lack the agent-specific features like programmatic access, file locks for concurrent agents, and Intelligence Mode for automatic indexing.

Fastio provides workspaces designed for this agent-to-human handoff. The Business Trial includes 50 GB of storage, included credits, and 5 workspaces with no credit card required. The MCP server exposes workspace operations that an agent can call directly, and Intelligence Mode auto-indexes uploaded files so your team can search and chat with agent output immediately.

For an OpenClaw Lambda deployment, the practical pattern is: the agent does its work using S3 for session state, then uploads final deliverables to a Fastio workspace where humans pick them up. The ownership transfer feature lets the agent build an entire workspace, populate it with files, and then transfer the organization to a human who takes over from there.

File locks prevent conflicts when multiple Lambda invocations or multiple agents write to the same workspace concurrently. This matters in serverless architectures where you cannot predict how many instances are running at any given moment.

How to Choose the Right Deployment Path

The best option depends on your scale, budget, and how many users need access to the agent.

Pick Lambda Containers if you are running a personal agent or building a prototype. The cost is nearly zero at low volumes, the cold start is acceptable for chat interactions, and the CDK template gets you running in under an hour. Just be aware of the alpha status and set budget alarms.

Pick Bedrock AgentCore if you are deploying for a team or building a customer-facing bot. Per-user isolation, content guardrails, and the async automation hooks pattern make it production-ready. The tradeoff is complexity: 8 CDK stacks, more AWS services to manage, and higher baseline costs from guardrails and cross-region inference.

Pick Fargate Spot as a fallback for long-running tasks. Lambda has a 15-minute execution timeout. If your agent needs to perform extended research, process large files, or run multi-step workflows that take longer than 15 minutes, Fargate Spot provides containers without the timeout constraint at 70% less cost than on-demand Fargate.

Consider staying on a VPS if your agent runs continuously and handles steady traffic. A $5/month Lightsail instance with a prebuilt OpenClaw blueprint is simpler to operate than a serverless stack, and the cost is predictable. Serverless only saves money when utilization is bursty or low.

Cost Decision Framework

If your agent handles fewer than 10,000 requests per month, Lambda Containers will cost less than any fixed-cost alternative. Between 10,000 and 100,000 requests, compare your Lambda bill against a reserved Lightsail or EC2 instance. Above 100,000 requests, a dedicated instance with Graviton processors (which AWS documentation notes can save 20-40% on compute versus x86) is almost cheaper.

The real cost driver is not compute but LLM API calls. A single Claude Sonnet request costs more than thousands of Lambda invocations. Set token budget alarms regardless of which deployment path you choose.

Frequently Asked Questions

How do I deploy OpenClaw on AWS Lambda?

Package OpenClaw as a Lambda Container image using the serverless-openclaw CDK template. The project deploys API Gateway, Lambda, DynamoDB, S3, CloudFront, and Cognito with a single CDK command. Configure your environment variables, run the build, and deploy. The project includes unit and integration tests to verify your configuration before going live.

What is the cheapest way to run OpenClaw on AWS?

Lambda Containers offer the lowest cost for low-traffic agents. At 100 requests per month with an average duration of 1.5 seconds, Lambda compute costs about $0.01/month. The serverless-openclaw project targets roughly $1/month total including all supporting services. The key cost savings come from using API Gateway instead of an ALB (which adds $18-25/month in fixed costs) and automatic container termination when idle.

Can OpenClaw run serverlessly?

Yes. OpenClaw can run on AWS Lambda as a container image, on Bedrock AgentCore as a managed serverless runtime, or on Fargate Spot for longer-running tasks. Each approach handles the stateless nature of serverless differently: Lambda uses S3 with DynamoDB concurrency control for session persistence, while AgentCore syncs a .openclaw/ directory to S3 across sessions automatically.

What is the cold start time for OpenClaw on Lambda?

The serverless-openclaw project reports a cold start of approximately 1.35 seconds for Lambda Container deployment, with warm responses at 0.12 seconds. You can eliminate cold starts entirely by scheduling EventBridge pre-warm invocations during business hours, which adds roughly $0.07/month using Spot pricing.

How does OpenClaw handle session state on Lambda?

Since Lambda functions are stateless, OpenClaw session data is persisted to S3 after each invocation and loaded back on the next request. DynamoDB provides concurrency control to prevent race conditions when multiple requests arrive at the same time. This pattern works well for sequential chat interactions.

What is the difference between Lambda and Bedrock AgentCore for OpenClaw?

Lambda Containers are best for single-user personal agents with minimal cost. Bedrock AgentCore is built for multi-user production deployments with per-user Firecracker microVM isolation, built-in content guardrails, async automation hooks processing, and comprehensive observability. AgentCore has longer cold starts (5-15 seconds for lightweight agents) but provides stronger security and operational controls.

Related Resources

Fastio features

Persist your serverless agent's output where your team can use it

generous storage workspace with MCP access, auto-indexing, and ownership transfer. No credit card, no trial expiration.