Skip to main content
Version: 0.2.0

AWS Serverless Deployment

Deploy agents to AWS Lambda for auto-scaling, serverless execution.

Architecture

Prerequisites

  • AWS CLI configured
  • AWS credentials with Lambda/API Gateway permissions
  • Agent Kernel with AWS extras: pip install agentkernel[aws]

Deployment

1. Install Dependencies

pip install agentkernel[aws,openai]

2. Configure

Refer to Terraform modules for configuration details.

3. Deploy

terraform init && terraform deploy

Lambda Handler

Your agent code remains the same, just import the Lambda handler:

from agents import Agent as OpenAIAgent
from agentkernel.openai import OpenAIModule
from agentkernel.aws import Lambda

agent = OpenAIAgent(name="assistant", ...)
OpenAIModule([agent])

handler = Lambda.handler
## API Endpoints

After deployment:

POST https://{api-id}.execute-api.us-east-1.amazonaws.com/prod/chat

Body:

{
"agent": "assistant",
"message": "Hello!",
"session_id": "user-123"
}

Cost Optimization

Lambda Configuration

Memory: 512 MB Timeout: 30

Refer to Terraform modules to update the configurations.

Cold Start Mitigation

  • Use provisioned concurrency for critical endpoints
  • Keep Lambda warm with scheduled pings
  • Optimize package size

Session Storage

Use ElastiCache Redis for session persistence:

export AK_SESSION_STORAGE=redis
export AK_REDIS_URL=redis://elasticache-endpoint:6379

Monitoring

CloudWatch metrics automatically available:

  • Invocation count
  • Duration
  • Errors
  • Concurrent executions

Best Practices

  • Use Redis for session storage (not in-memory)
  • Set appropriate timeout (30-60s for LLM calls)

Example Deployment

See examples/aws-serverless