Writing Policies
💡 Don't want to write YAML? Create policies with AI instead →
SOFE policies are YAML files that define rules for your cloud resources. Here's how to write your own.
Policy Schema
apiVersion: sofe/v1 # always sofe/v1
kind: Policy # always Policy
metadata:
name: my-policy-name # unique identifier (kebab-case)
description: "Human-readable description"
author: you@email.com
tags: [cost-optimization, compute]
spec:
scope: # WHAT resources to check
resource_types: [aws.ec2] # one or more collector types
regions: ["*"] # or specific: [us-east-1, eu-west-1]
accounts: ["*"] # or specific account IDs
environments: ["*"] # filter by tag:Environment
rule: # WHEN to flag a violation
metric: avg_cpu_utilization # metric from collector
period: 30d # evaluation window (optional)
operator: "<" # <, >, ==, !=, <=, >=
threshold: 5 # numeric value
severity: high # critical | high | medium | low | info
actions: # WHAT to do on violation
- type: finding # always include (produces output)
- type: recommend
suggestion: "Rightsize or terminate"
estimated_savings: calc # engine calculates savingsAvailable Metrics (by Collector)
| Collector | Metrics |
|---|---|
| aws.ec2 | avg_cpu_utilization, monthly_cost, running_days, has_tag:* |
| aws.s3 | monthly_cost, has_lifecycle_rules, encryption_enabled, has_tag:* |
| aws.rds | avg_connections, monthly_cost, has_tag:* |
| aws.ebs | attached, monthly_cost, snapshot_age_days |
| aws.elb | has_targets, waf_enabled, monthly_cost |
| aws.natgateway | monthly_cost |
| aws.dynamodb | provisioned_utilization_percent, monthly_cost |
| aws.sagemaker | invocations_per_day, monthly_cost |
| aws.secretsmanager | rotation_enabled |
| aws.cloudfront | compression_enabled, monthly_cost |
| aws.apigateway | throttle_configured, monthly_cost |
| aws.ecs | avg_cpu_utilization, running_count |
Examples
Tag governance
spec:
scope: { resource_types: ["*"] }
rule: { metric: "has_tag:costCenter", operator: "==", threshold: 0 }
severity: mediumBudget alert
spec:
scope: { resource_types: ["*"] }
rule: { metric: budget_utilization_percent, operator: ">", threshold: 80 }
severity: criticalIdle load balancer
spec:
scope: { resource_types: [aws.elb] }
rule: { metric: has_targets, operator: "==", threshold: 0 }
severity: medium
actions:
- type: finding
- type: recommend
suggestion: "Delete this idle LB — no targets registered"Validate Your Policy
sofe validate --policies ./my-policies/