Serverless & Edge Computing

Serverless Cost Optimization

Serverless does not mean free. A misconfigured Lambda function running at 3GB memory for a 50ms task, a DynamoDB table with over-provisioned capacity, or an API Gateway without caching can blow your budget. We audit your serverless infrastructure, identify the top cost drivers, and implement optimizations that typically reduce your monthly bill by 40–70% without impacting performance.

Need this done for your project?

We implement, you ship. Async, documented, done in days.

Start a Brief

Lambda Cost Analysis & Right-Sizing

We start by analyzing every Lambda function's actual resource utilization using CloudWatch metrics and AWS Lambda Power Tuning.

# Step 1: Identify over-provisioned functions
# CloudWatch Insights query
filter @type = "REPORT"
| stats
    count() as invocations,
    avg(@maxMemoryUsed / 1048576) as avgMemoryMB,
    max(@maxMemoryUsed / 1048576) as maxMemoryMB,
    avg(@duration) as avgDurationMs,
    pct(@duration, 99) as p99DurationMs,
    avg(@billedDuration * @memorySize / 1048576 / 1024) as avgGBSeconds
  by @log
| sort avgGBSeconds desc
| limit 20

# Common findings:
# - Function allocated 1024MB, uses max 180MB → reduce to 256MB
# - Function runs 15ms avg but timeout is 300s → reduce to 10s
# - Function invoked 1M times but 800K are cache-hittable

We run Power Tuning on every function with more than 10,000 monthly invocations. The tool tests the function at 8 different memory configurations and reports the optimal setting for either cost or performance. We typically find that 60% of functions are over-provisioned by 2-4x.

DynamoDB Capacity Optimization

DynamoDB billing mode selection is the biggest single cost lever for most serverless applications.

# On-Demand vs Provisioned cost comparison
# Workload: 1,000 writes/sec sustained, 3,000 reads/sec sustained

# On-Demand pricing:
#   Writes: 1,000 * 3600 * 24 * 30 = 2.59B WRUs/mo = $3,370/mo
#   Reads:  3,000 * 3600 * 24 * 30 = 7.78B RRUs/mo = $1,944/mo
#   Total: $5,314/mo

# Provisioned with auto-scaling:
#   Writes: 1,000 WCU * $0.47/WCU = $470/mo
#   Reads:  3,000 RCU * $0.09/RCU = $270/mo
#   Total: $740/mo → 86% savings

# Recommendation threshold:
# - Unpredictable, spiky traffic → On-Demand
# - Predictable, sustained traffic → Provisioned + Auto-Scaling
# - Mixed → Provisioned base + On-Demand burst

resource "aws_appautoscaling_policy" "dynamodb_writes" {
  name               = "dynamodb-write-scaling"
  policy_type        = "TargetTrackingScaling"
  resource_id        = "table/${var.table_name}"
  scalable_dimension = "dynamodb:table:WriteCapacityUnits"
  service_namespace  = "dynamodb"

  target_tracking_scaling_policy_configuration {
    target_value       = 70.0  # Scale at 70% utilization
    scale_in_cooldown  = 60
    scale_out_cooldown = 10   # Scale out fast
  }
}

We also analyze GSI usage. Unused or over-projected GSIs waste capacity. We audit every GSI against actual query patterns and remove or reduce projections where possible.

API Gateway & Data Transfer Savings

API Gateway is $1 per million requests for HTTP API — cheap at low volume, significant at scale. We implement caching and request reduction strategies.

# API Gateway caching — reduces Lambda invocations
resource "aws_api_gateway_method_settings" "cache" {
  rest_api_id = aws_api_gateway_rest_api.main.id
  stage_name  = aws_api_gateway_stage.prod.stage_name
  method_path = "products/GET"

  settings {
    caching_enabled        = true
    cache_ttl_in_seconds   = 300
    cache_data_encrypted   = true
    require_authorization_for_cache_control = true
  }
}

# CloudFront in front of API Gateway for edge caching
resource "aws_cloudfront_distribution" "api" {
  origin {
    domain_name = "${aws_apigatewayv2_api.http.id}.execute-api.${var.region}.amazonaws.com"
    origin_id   = "api-gateway"
    custom_origin_config {
      http_port              = 80
      https_port             = 443
      origin_protocol_policy = "https-only"
      origin_ssl_protocols   = ["TLSv1.2"]
    }
  }
  
  default_cache_behavior {
    allowed_methods        = ["GET","HEAD","OPTIONS","PUT","POST","PATCH","DELETE"]
    cached_methods         = ["GET","HEAD"]
    target_origin_id       = "api-gateway"
    viewer_protocol_policy = "redirect-to-https"
    cache_policy_id        = aws_cloudfront_cache_policy.api.id
    compress               = true
  }
}

CloudFront in front of API Gateway reduces data transfer costs (CloudFront egress is cheaper than API Gateway egress) and offloads GET requests entirely. For APIs with high read-to-write ratios, this cuts Lambda invocations by 50–80%.

Cost Monitoring & Alerting

We set up continuous cost monitoring so you catch cost anomalies within hours, not at the end of the month.

resource "aws_budgets_budget" "serverless" {
  name         = "serverless-monthly"
  budget_type  = "COST"
  limit_amount = "500"
  limit_unit   = "USD"
  time_unit    = "MONTHLY"

  cost_filter {
    name   = "Service"
    values = [
      "AWS Lambda",
      "Amazon API Gateway",
      "Amazon DynamoDB",
      "Amazon Simple Queue Service",
    ]
  }

  notification {
    comparison_operator       = "GREATER_THAN"
    threshold                 = 80
    threshold_type            = "PERCENTAGE"
    notification_type         = "ACTUAL"
    subscriber_email_addresses = [var.alert_email]
  }
  
  notification {
    comparison_operator       = "GREATER_THAN"
    threshold                 = 100
    threshold_type            = "PERCENTAGE"
    notification_type          = "FORECASTED"
    subscriber_email_addresses = [var.alert_email]
  }
}

# Cost anomaly detection
resource "aws_ce_anomaly_monitor" "serverless" {
  name              = "serverless-anomaly"
  monitor_type      = "DIMENSIONAL"
  monitor_dimension = "SERVICE"
}

resource "aws_ce_anomaly_subscription" "alert" {
  name      = "serverless-anomaly-alert"
  frequency = "IMMEDIATE"
  monitor_arn_list = [aws_ce_anomaly_monitor.serverless.arn]
  threshold_expression {
    dimension {
      key           = "ANOMALY_TOTAL_IMPACT_ABSOLUTE"
      values        = ["50"]
      match_options = ["GREATER_THAN_OR_EQUAL"]
    }
  }
  subscriber {
    type    = "EMAIL"
    address = var.alert_email
  }
}

AWS Cost Anomaly Detection uses ML to identify unusual spending patterns and alerts you within hours. We tag every resource with project, service, and environment tags for granular cost attribution in Cost Explorer. Monthly cost reports are exported to S3 for historical analysis and trend tracking.

Why Anubiz Engineering

100% async — no calls, no meetings
Delivered in days, not weeks
Full documentation included
Production-grade from day one
Security-first approach
Post-delivery support included

Ready to get started?

Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.