Skip to main content

Cloud Deployment

Deploy to any cloud provider Korad.AI runs on AWS, GCP, Azure, and more.

AWS Deployment​

AWS ECS​

1. Push to ECR​

# Login to ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account-id>.dkr.ecr.us-east-1.amazonaws.com

# Tag and push
docker tag koradai/bifrost-optimizer:latest <account-id>.dkr.ecr.us-east-1.amazonaws.com/bifrost-optimizer:latest
docker push <account-id>.dkr.ecr.us-east-1.amazonaws.com/bifrost-optimizer:latest

2. Create Task Definition​

{
"family": "bifrost-optimizer",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "512",
"memory": "1024",
"containerDefinitions": [
{
"name": "optimizer",
"image": "<account-id>.dkr.ecr.us-east-1.amazonaws.com/bifrost-optimizer:latest",
"portMappings": [{"containerPort": 8084}],
"environment": [
{"name": "REDIS_URL", "value": "redis-cluster.xxxxxx.use1.cache.amazonaws.com:6379"},
{"name": "DATABASE_URL", "value": "postgres://..."}
],
"secrets": [
{"name": "ANTHROPIC_API_KEY", "valueFrom": "arn:aws:secretsmanager:...:anthropic-key"}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/bifrost",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "optimizer"
}
}
}
]
}

3. Create Service​

aws ecs create-service \
--cluster bifrost-cluster \
--service-name bifrost-optimizer \
--task-definition bifrost-optimizer \
--desired-count 2 \
--launch-type FARGATE \
--network-configuration "awsvpcConfiguration={subnets=[subnet-xxx,subnet-yyy],securityGroups=[sg-xxx],assignPublicIp=ENABLED}"

AWS Lambda (Serverless)​

import json

def lambda_handler(event, context):
# Import optimizer
from bifrost_optimizer import optimize_request

# Process request
result = optimize_request(event)

return {
'statusCode': 200,
'body': json.dumps(result)
}

Google Cloud Run​

1. Build and Push​

# Build image
gcloud builds submit --tag gcr.io/PROJECT_ID/bifrost-optimizer

# Deploy to Cloud Run
gcloud run deploy bifrost-optimizer \
--image gcr.io/PROJECT_ID/bifrost-optimizer \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars REDIS_URL=redis-instance:6379 \
--set-secrets ANTHROPIC_API_KEY=anthropic-key:latest

2. Configure​

# Set environment variables
gcloud run services update bifrost-optimizer \
--set-env-vars PROFIT_MARGIN=1.5

# Set secrets
gcloud secrets create anthropic-key --data-file=key.txt
gcloud run services update bifrost-optimizer \
--set-secrets ANTHROPIC_API_KEY=anthropic-key:latest

Azure Container Instances​

1. Create Container Group​

az container create \
--resource-group bifrost-rg \
--name bifrost-optimizer \
--image koradai/bifrost-optimizer:latest \
--cpu 2 \
--memory 4 \
--ports 8084 \
--environment-variables \
REDIS_URL=redis-instance:6379 \
DATABASE_URL=postgres://... \
--secure-environment-variables \
ANTHROPIC_API_KEY=sk-ant-xxx

2. Configure DNS​

# Add custom domain
az container show \
--resource-group bifrost-rg \
--name bifrost-optimizer \
--query ipAddress.fqdn

DigitalOcean​

1. Create Droplet​

# Create droplet
doctl compute droplet create bifrost-optimizer \
--region nyc1 \
--image ubuntu-22-04-x64 \
--size s-4vcpu-8gb \
--ssh-keys <fingerprint>

2. Deploy with Docker​

# SSH into droplet
ssh root@droplet-ip

# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

# Clone repo
git clone https://github.com/koradai/bifrost.git
cd bifrost

# Deploy
docker-compose up -d

Fly.io​

1. Install Fly CLI​

curl -L https://fly.io/install.sh | sh

2. Deploy​

# Login
fly auth login

# Launch app
fly launch --region ord

# Set secrets
fly secrets set ANTHROPIC_API_KEY=sk-ant-xxx
fly secrets set DATABASE_URL=postgres://...

# Deploy
fly deploy

Managed Services​

Redis​

ProviderService
AWSElastiCache
GCPMemorystore
AzureAzure Cache for Redis
DigitalOceanRedis

PostgreSQL​

ProviderService
AWSRDS
GCPCloud SQL
AzureDatabase for PostgreSQL
NeonNeon Serverless Postgres

Monitoring​

CloudWatch (AWS)​

import boto3

cloudwatch = boto3.client('cloudwatch')

# Publish custom metrics
cloudwatch.put_metric_data(
Namespace='Bifrost/Optimizer',
MetricData=[{
'MetricName': 'OptimizationRate',
'Value': 0.78,
'Unit': 'Percent'
}]
)

Cloud Monitoring (GCP)​

from google.cloud import monitoring_v3

client = monitoring_v3.MetricServiceClient()

# Write metric
series = monitoring_v3.TimeSeries()
# ... configure series ...
client.create_time_series(name=series.name, time_series=[series])

Security​

1. Use Secrets Manager​

  • AWS Secrets Manager
  • GCP Secret Manager
  • Azure Key Vault
  • Doppler (multi-cloud)

2. Enable HTTPS​

# AWS Certificate Manager
aws acm request-certificate --domain-name api.korad.ai

# GCP Certificate (gcloud)
gcloud compute ssl-certificates create bifrost-cert --domains api.korad.ai

3. Network Isolation​

# VPC configuration
securityGroups:
- inbound:
- port: 8084
source: loadbalancer
- outbound:
- destination: redis
- destination: database

Scaling​

Auto Scaling​

AWS​

aws application-autoscaling register-scalable-target \
--service-namespace ecs \
--resource-id service/bifrost-cluster/bifrost-optimizer \
--scalable-dimension ecs:service:DesiredCount \
--min-capacity 2 \
--max-capacity 10

GCP Cloud Run​

# Set max instances
gcloud run services update bifrost-optimizer \
--max-instances 10 \
--min-instances 2

Cost Optimization​

1. Use Spot Instances​

# AWS Fargate Spot
aws ecs create-service \
--capacity-provider-strategy FARGATE_SPOT

2. Right-Size Resources​

# Start small, scale as needed
resources:
limits:
cpus: '0.5'
memory: 512M

3. Use Serverless​

  • AWS Lambda
  • GCP Cloud Run
  • Azure Container Instances

Deploy Korad.AI to any cloud provider.