DEV Community

Cloud Frontier
Cloud Frontier

Posted on

Cutting Cloud Costs with a Few Habits

The Cloud Bill Isn't a Mystery

Every month, the same shock. The cloud bill arrives, and it's higher than expected. I used to blame the provider, then my team, then the phase of the moon. But after years of cleaning up messes, I realized the problem isn't the cloud - it's our habits. A few small changes in how we deploy, monitor, and think about resources can cut costs dramatically without sacrificing performance.

Habit 1: Right-Size Everything, Regularly

Your instances are probably oversized. We tend to pick a size that feels safe, then never revisit it. I've seen production boxes running at 10% CPU for months. That's money burning for no reason.

The habit: Every quarter, check your usage metrics. Look at CPU, memory, and network. If an instance has been under 20% utilization for 30 days, downgrade it. Automate this if you can - some providers offer rightsizing recommendations.

# Quick check with AWS CLI (example)
aws cloudwatch get-metric-statistics --namespace AWS/EC2 \
  --metric-name CPUUtilization --dimensions Name=InstanceId,Value=i-1234567890 \
  --start-time 2024-01-01T00:00:00Z --end-time 2024-01-31T00:00:00Z \
  --period 86400 --statistics Average
Enter fullscreen mode Exit fullscreen mode

If you're using Kubernetes, look at kubectl top nodes and adjust your resource requests. The goal is to match capacity to actual demand, not to your fear of a spike.

Habit 2: Turn Off What You're Not Using

Development and staging environments are the worst offenders. They run 24/7, but nobody touches them after 6 PM. I once found a test database that hadn't been queried in three months. It was costing $400 a month.

The habit: Implement a schedule. Shut down non-production resources outside business hours. Use a simple cron job or a cloud function to stop instances at 7 PM and start them at 7 AM.

# Example: AWS Lambda with boto3 to stop instances tagged 'dev' after hours
import boto3

def stop_dev_instances(event, context):
    ec2 = boto3.client('ec2')
    reservations = ec2.describe_instances(
        Filters=[{'Name': 'tag:Environment', 'Values': ['dev']}]
    )
    for reservation in reservations['Reservations']:
        for instance in reservation['Instances']:
            if instance['State']['Name'] == 'running':
                ec2.stop_instances(InstanceIds=[instance['InstanceId']])
                print(f"Stopped {instance['InstanceId']}")
Enter fullscreen mode Exit fullscreen mode

Make it a policy: if a resource isn't used for a week, it gets deleted or stopped. You can always start it again later.

Habit 3: Use Managed Services Wisely

Managed services like RDS, ElastiCache, or Cloud SQL are convenient, but they come with a premium. Sometimes that premium is worth it. Often, it isn't.

The habit: For every managed service, ask: "Can I run this myself with a small VM?" If the answer is yes and you have the operational capacity, consider self-hosting. For example, a small PostgreSQL database on a t3.micro might cost $15/month, while RDS for the same workload could be $30.

But don't go overboard. If you have a team that can't handle patching, backups, and failover, the managed service is worth the extra cost. The key is to make a conscious choice, not a default one.

Habit 4: Set Budgets and Alerts

You can't manage what you don't measure. I've seen teams get a $10,000 surprise because they never set up billing alerts. That's a painful way to learn.

The habit: Set a monthly budget for each project or environment. Configure alerts at 50%, 80%, and 100% of that budget. Most cloud providers have this built in. If you're on AWS, use Budgets; on GCP, use Budgets and Alerts; on Azure, use Cost Management.

# AWS CLI example: create a budget alert
aws budgets create-budget --account-id 123456789012 \
  --budget '{"BudgetName":"monthly-prod","BudgetLimit":{"Amount":"5000","Unit":"USD"},"TimeUnit":"MONTHLY","BudgetType":"COST"}' \
  --notifications '[{"NotificationType":"ACTUAL","ComparisonOperator":"GREATER_THAN","Threshold":80,"ThresholdType":"PERCENTAGE","NotificationState":"ALARM"}]'
Enter fullscreen mode Exit fullscreen mode

When an alert fires, don't ignore it. Investigate immediately. Usually, it's a runaway resource or a forgotten instance.

Habit 5: Review Your Storage and Snapshots

Storage is sneaky. You take a snapshot once, and then it grows forever. Old backups pile up. Orphaned volumes sit there charging you.

The habit: Once a month, list all your storage resources. Delete snapshots older than 30 days unless you have a compliance reason to keep them. Remove unattached volumes. Use lifecycle policies to automate this.

# List unattached EBS volumes (AWS example)
aws ec2 describe-volumes --filters Name=status,Values=available
Enter fullscreen mode Exit fullscreen mode

For object storage like S3, enable lifecycle rules to transition old files to cheaper tiers (like Glacier) or delete them after a set period.

The Real Cost of Bad Habits

These aren't one-time fixes. They're habits. The first month you'll save a little. The second month, more. Over a year, you'll be surprised at how much you've cut. But the real benefit is the mindset shift: you start thinking about cost as a first-class citizen, not an afterthought.

I've seen teams cut their cloud bill by 40% just by doing these five things consistently. No magic, no expensive software. Just habits.

Start with one. Pick the one that hurts the most, and make it a routine. Your future self (and your finance team) will thank you.

Top comments (0)