Back to Blog
Cloud & DevOps
July 5, 2026
6 min read

Guide to optimizing infrastructure costs in AWS and Google Cloud

Tomás Ledesma
Tomás Ledesma
Founder & Software Architect
Guide to optimizing infrastructure costs in AWS and Google Cloud

In the rush to scale quickly, many startups and established businesses deploy oversized resources in AWS or Google Cloud. The result at the end of the month is an exorbitant bill that drains the profit margin. However, auditing and cutting these unnecessary costs does not have to compromise the performance or availability of your systems.

The key lies in applying FinOps (cloud financial operations) principles and optimizing infrastructure programmatically and continuously.

1. Serverless and Real Pay-Per-Use

One of the most effective ways to reduce costs is to migrate workloads from 24/7 virtual servers (such as EC2 instances or traditional VMs) to pay-per-use serverless services like AWS Lambda, Google Cloud Run, or databases like DynamoDB. If a processing script only runs 2 hours a day, why pay for the other 22?

2. Automatic Shutdown of Development Environments

Want to optimize your technology?

We design and build bespoke AI automation pipelines and cloud architectures.

In most companies, development and testing environments (QA, staging) are not used during nights or weekends. Automating the shutdown and startup of these environments can instantly reduce up to 65% of their associated costs.

python
# Script to shutdown development instances outside business hours
import boto3

ec2 = boto3.client('ec2', region_name='eu-west-1')

def lambda_handler(event, context):
    # Filter instances tagged with 'Environment: Development'
    filters = [{
        'Name': 'tag:Environment',
        'Values': ['Development']
    }]
    
    # Get active running instances
    instances = ec2.describe_instances(Filters=filters)
    instance_ids = []
    
    for reservation in instances['Reservations']:
        for instance in reservation['Instances']:
            if instance['State']['Name'] == 'running':
                instance_ids.append(instance['InstanceId'])
    
    if instance_ids:
        ec2.stop_instances(InstanceIds=instance_ids)
        print(f"Successfully stopped instances: {instance_ids}")
    else:
        print("No active development instances found.")

3. Right-sizing

The most common oversizing error is allocating resources based on highly unlikely theoretical peaks. Instead, it is preferable to use auto-scaling (Autoscaling Groups) to adapt capacity dynamically, and monitor real CPU and memory metrics using tools like AWS Compute Optimizer to adjust the size of databases and hard drives to their actual load.

Related Articles

Frontend

Why Zustand is the best alternative to Redux in React

We compare Zustand against Redux Toolkit for state management in React, analyzing simplicity, performance, and the massive reduction of boilerplate.

Read post
Backend

Guide to structuring efficient microservices with FastAPI and Docker

Learn how to containerize your Python APIs with Docker, optimizing image sizes using multi-stage builds and accelerating your deployments.

Read post
Tomás Ledesma
Written by

Tomás Ledesma

Tomás Ledesma is a software architect and technical consultant specializing in intelligent process automation, scalable cloud architectures, and cross-platform app engineering.