AWS Cost Optimization: EC2, RDS, and S3 Strategies
Cloud 14 min read

AWS Cost Optimization: EC2, RDS, and S3 Strategies

Cloud infrastructure makes it possible to provision computing, databases, and storage without purchasing physical hardware. Teams can scale resources when demand increases and reduce them when demand falls.

However, the convenience of provisioning resources can also make infrastructure spending difficult to control.

An application may begin with one EC2 instance, a small RDS database, and an S3 bucket. Over time, the system accumulates additional environments, larger instances, snapshots, backups, load balancers, storage requests, and data transfer.

Some resources remain active after the workload that required them has disappeared. Others are provisioned with more capacity than the application needs. A database may be configured for high availability even when the application does not have a corresponding availability requirement, or storage may retain old data indefinitely.

The result is an AWS bill that grows faster than the value delivered by the infrastructure.

Cost optimization is not simply about choosing the cheapest instance or moving every file into an archive tier. It is about matching resource consumption to actual workload requirements while preserving performance, availability, security, and recovery capability.

This article focuses on three important AWS services: Amazon EC2, Amazon RDS, and Amazon S3. It also explores cross-service governance, monitoring, and a practical cost-review process.

1. Start With Visibility Before Making Changes

The first step in cost optimization is understanding where money is being spent.

Reducing the size of a resource without understanding its workload can create performance problems. Deleting storage without checking retention requirements can destroy important recovery data.

Start by reviewing:

  • Which AWS services contribute most to the bill?
  • Which resources have low utilization?
  • Which environments are always running?
  • Which storage objects are rarely accessed?
  • Are backups and snapshots accumulating?
  • Is data transfer creating unexpected charges?
  • Are resources properly tagged?
  • Are there unused or duplicated environments?

AWS Cost Explorer

AWS Cost Explorer provides views of historical costs and usage. Teams can group costs by service, account, Region, usage type, and other available dimensions.

For example, a team can compare monthly EC2, RDS, and S3 expenditure to identify which service deserves investigation first.

Use cost allocation tags

Tags help associate infrastructure spending with the systems and teams that consume it.

Example:

Environment = production
Project = customer-platform
Team = engineering
Owner = platform-team
CostCenter = operations

Tags are useful only when applied consistently. Establish a naming policy and include tags in infrastructure templates rather than relying on engineers to remember them manually.

Establish a baseline

Before changing resources, record:

  • Monthly service costs
  • Instance utilization
  • Database CPU and storage usage
  • S3 storage volume
  • Request and retrieval patterns
  • Data transfer
  • Backup and snapshot volume
  • Availability and performance requirements

This baseline makes it possible to evaluate whether an optimization actually improves the system.

2. EC2 Cost Optimization

Amazon EC2 provides virtual compute capacity. Its cost depends on factors such as instance type, operating system, Region, purchase model, attached storage, and the time resources remain active.

A cost-efficient EC2 environment begins with selecting the right capacity for the workload.

Right-sizing instances

Right-sizing means matching instance resources to application demand.

An instance with too little memory may experience swapping, slow response times, or application instability. An oversized instance may remain mostly idle while generating unnecessary expenditure.

Review metrics such as:

  • CPU utilization
  • Memory utilization
  • Network throughput
  • Disk I/O
  • Application response time
  • Request volume
  • Peak and average workload

Do not make the decision based on CPU alone. A database, cache, or memory-intensive service may be constrained by resources that basic CPU graphs do not reveal.

Select the appropriate instance family

AWS offers different instance families for different workload characteristics.

Examples include:

  • General-purpose instances for balanced workloads
  • Compute-optimized instances for CPU-intensive workloads
  • Memory-optimized instances for memory-heavy applications
  • Storage-optimized instances for workloads requiring high local storage performance
  • Accelerated computing instances for specialized processing

Selecting the cheapest available instance is not the objective. The objective is to minimize the total cost of meeting the workload's performance and availability requirements.

Evaluate purchase options

Model Typical use
On-Demand Variable or uncertain workloads
Savings Plans Predictable usage with a spending commitment
Reserved Instances Workloads that fit the reservation's configuration and terms
Spot Instances Interruptible workloads
Dedicated Hosts Specific licensing or tenancy requirements

On-Demand: A useful starting point when usage is uncertain. It avoids long-term commitments but may cost more for sustained workloads.

Savings Plans: Can reduce costs when the organization has predictable eligible usage. A commitment should be based on historical consumption and realistic forecasts.

Reserved Instances: May be appropriate when the required configuration and service usage are stable. Understand the applicable flexibility and payment terms before purchasing.

Spot Instances: Useful for workloads that can tolerate interruption, such as batch processing, fault-tolerant workers, and certain data-processing tasks. Do not place a critical, non-interruptible workload on Spot Instances simply to reduce its hourly cost.

Use Auto Scaling

An application that experiences changing traffic may not need the same number of instances throughout the day.

An EC2 Auto Scaling group can adjust capacity based on defined policies and metrics.

A simplified Terraform example:

resource "aws_launch_template" "app" {
  name_prefix   = "customer-app-"
  image_id      = var.ami_id
  instance_type = "t3.medium"
  
  tag_specifications {
    resource_type = "instance"
    
    tags = {
      Project     = "customer-app"
      Environment = "production"
    }
  }
}

resource "aws_autoscaling_group" "app" {
  name                = "customer-app-asg"
  min_size            = 2
  max_size            = 6
  desired_capacity    = 2
  vpc_zone_identifier = var.private_subnet_ids
  
  launch_template {
    id      = aws_launch_template.app.id
    version = "$Latest"
  }
}

This example defines capacity boundaries, but it does not yet configure scaling policies, health checks, or a load balancer.

Auto Scaling should respond to meaningful workload signals. Scaling on CPU alone may not be appropriate for every application.

Identify unused resources

Regularly investigate:

  • Stopped instances with attached EBS volumes
  • Unattached EBS volumes
  • Unused Elastic IP addresses
  • Old snapshots
  • Development instances running continuously
  • Abandoned load balancers
  • Duplicate test environments

Stopped EC2 instances may still incur storage-related charges because attached EBS volumes continue to exist.

3. RDS Cost Optimization

Amazon RDS simplifies the operation of relational databases, but database costs can grow because of compute capacity, storage, I/O, backups, deployment configuration, and data transfer.

Database optimization requires more caution than ordinary compute optimization because poorly planned changes can affect application performance and data availability.

Right-size database instances

Review:

  • CPU utilization
  • Freeable memory
  • Database connections
  • Read and write throughput
  • Storage consumption
  • I/O activity
  • Query latency
  • Connection pool behavior

A database instance that is consistently underutilized may be a candidate for a smaller class, but test the change under realistic workloads.

Understand Multi-AZ costs

Multi-AZ deployments provide high availability by maintaining resources in multiple Availability Zones.

However, the exact architecture matters. A traditional Multi-AZ DB instance deployment maintains a standby instance for failover. Multi-AZ DB clusters have a different architecture.

The important cost lesson is to select the deployment architecture based on the actual availability and read-scaling requirements.

Do not disable high availability solely to reduce cost if the application has a genuine requirement for resilient database operation.

Read replicas versus caching

Read replicas can help distribute read-heavy workloads, but they introduce additional database resources and operational complexity.

Before creating one, investigate whether the application is issuing inefficient queries or repeatedly requesting data that could be cached.

Consider:

  • Query optimization
  • Database indexes
  • Connection pooling
  • Application caching
  • Redis or another managed caching service
  • Read replicas for genuine read-scaling needs

Review storage and backups

Database storage can increase as tables, indexes, transaction logs, and retained backups grow.

Review:

  • Allocated storage
  • Storage autoscaling settings
  • Backup retention periods
  • Manual snapshots
  • Automated backup policies
  • Unused database instances
  • Monitoring and log retention

Never reduce backup retention without checking recovery objectives and organizational requirements.

Evaluate Reserved DB Instances

For stable database workloads, evaluate applicable RDS Reserved Instance options.

Compare the commitment against the database's expected lifetime, engine, Region, instance configuration, and payment terms.

4. S3 Cost Optimization

Amazon S3 is commonly used for application uploads, documents, backups, logs, media, static assets, and data archives.

Its cost is influenced by more than stored gigabytes. Depending on the storage class and workload, relevant charges can include:

  • Storage volume
  • Requests
  • Retrieval
  • Data transfer
  • Lifecycle transitions
  • Replication

Choose the right storage class

S3 Standard: Suitable for frequently accessed data requiring low-latency access.

S3 Intelligent-Tiering: Designed for data with changing or uncertain access patterns. It automatically moves eligible objects between access tiers.

S3 Standard-IA: Suitable for long-lived data accessed less frequently but still requiring rapid retrieval.

S3 One Zone-IA: Can suit data that is infrequently accessed and can be recreated if lost, because it is stored in a single Availability Zone.

S3 Glacier classes: Useful for archival data with different retrieval-time requirements.

Use lifecycle policies

Lifecycle policies automate transitions between storage classes and expiration of objects that no longer need to be retained.

Example configuration:

{
  "Rules": [
    {
      "ID": "archive-old-application-logs",
      "Status": "Enabled",
      "Filter": {
        "Prefix": "logs/"
      },
      "Transitions": [
        {
          "Days": 30,
          "StorageClass": "STANDARD_IA"
        },
        {
          "Days": 90,
          "StorageClass": "GLACIER"
        }
      ]
    }
  ]
}

Review data transfer costs

Data transfer is an important part of S3 cost analysis.

Investigate:

  • Repeated downloads
  • Cross-Region transfers
  • Cross-account access patterns
  • CDN configuration
  • Application architecture
  • Unnecessary movement of large objects

Delete obsolete objects carefully

Old logs, temporary exports, duplicate backups, and abandoned uploads may accumulate.

Before deleting data, establish:

  • Who owns it?
  • Is it still required?
  • Is it subject to retention requirements?
  • Is another backup available?
  • Can it be restored if needed?

5. Cross-Service Cost Controls

EC2, RDS, and S3 should not be optimized independently of the wider architecture.

Tagging and accountability

Create a consistent tagging policy for projects, environments, owners, and cost centers.

Use cost allocation reporting to understand which teams and products are consuming resources.

Budgets and alerts

AWS Budgets can help teams monitor actual and forecasted expenditure against configured thresholds.

Establish alerts for:

  • Monthly budget thresholds
  • Forecasted overspending
  • Unexpected service growth
  • New high-cost resources
  • Unusual usage patterns

Cost Anomaly Detection

AWS Cost Anomaly Detection uses machine learning to identify unusual spending patterns.

It should complement, not replace, budget controls and regular cost reviews.

Separate environments

Development, staging, and production environments often have different availability and capacity requirements.

For example:

  • Production may require high availability
  • Staging may need production-like configuration during release testing
  • Development may use smaller resources and scheduled shutdowns

6. A Practical Cost Review: Hypothetical Example

Consider a fictional business application with:

  • Two EC2 instances running continuously
  • An RDS database configured with more capacity than the workload requires
  • An S3 bucket storing application uploads and old logs
  • Separate development and staging environments

The monthly bill increases, but the engineering team has not changed the application significantly.

Area Observation Proposed investigation
EC2 Low average utilization Load-test a smaller instance
EC2 Development runs overnight Introduce scheduled shutdowns
RDS Database capacity exceeds demand Evaluate right-sizing
RDS Queries repeatedly request same data Test caching and query optimization
S3 Old logs remain in Standard Apply a reviewed lifecycle policy
S3 Temporary exports accumulate Introduce expiration rules
Governance Resources lack ownership tags Establish tagging enforcement

The team should implement one change at a time, measure its impact, and check that service quality remains acceptable.

7. Practical AWS CLI and Terraform Examples

Inspect EC2 instances

aws ec2 describe-instances \
  --query 'Reservations[].Instances[].{
    ID:InstanceId,
    Type:InstanceType,
    State:State.Name,
    AZ:Placement.AvailabilityZone
  }' \
  --output table

Inspect RDS databases

aws rds describe-db-instances \
  --query 'DBInstances[].{
    Identifier:DBInstanceIdentifier,
    Class:DBInstanceClass,
    Engine:Engine,
    Storage:AllocatedStorage,
    MultiAZ:MultiAZ
  }' \
  --output table

Terraform example: S3 lifecycle configuration

resource "aws_s3_bucket_lifecycle_configuration" "logs" {
  bucket = aws_s3_bucket.application_logs.id
  
  rule {
    id     = "archive-old-logs"
    status = "Enabled"
    
    filter {
      prefix = "logs/"
    }
    
    transition {
      days          = 30
      storage_class = "STANDARD_IA"
    }
    
    transition {
      days          = 90
      storage_class = "GLACIER"
    }
    
    expiration {
      days = 365
    }
  }
}

8. Build a Continuous Cost Optimization Process

Cost optimization should not be a one-time exercise performed after an unexpectedly large invoice arrives.

A practical monthly process can include:

  1. Review expenditure: Compare current and previous billing periods
  2. Investigate utilization: Review EC2, RDS, and storage metrics
  3. Review architecture: Check for unnecessary demand
  4. Evaluate commitments: Use actual workload history
  5. Apply controlled changes: Test in non-production first
  6. Measure results: Compare cost, performance, availability
  7. Automate governance: Use templates, tags, alerts

Key Takeaways

  • AWS cost optimization begins with visibility into actual service consumption
  • EC2 right-sizing, appropriate purchase models, and Auto Scaling can reduce unnecessary compute expenditure
  • RDS optimization must balance instance capacity, database performance, high availability, backups, and recovery requirements
  • S3 storage classes and lifecycle policies should reflect actual data access and retention patterns
  • Budgets, tagging, Cost Explorer, and anomaly detection help make cost management an ongoing engineering responsibility

Conclusion: An efficient cloud environment is not necessarily the one with the fewest resources or the lowest possible monthly bill. It is the environment that delivers the required performance, reliability, security, and recovery capability without paying for capacity or services that provide no meaningful value. EC2, RDS, and S3 offer several ways to align infrastructure consumption with real workload requirements. The challenge is choosing the right combination, measuring the outcome, and maintaining the improvements as the application evolves. Cost optimization is therefore an engineering discipline. It belongs in architecture reviews, deployment planning, infrastructure automation, and regular operational monitoring—not just in the finance department.


Published by the DSSS Engineering Team. For corrections or topic requests, use the contact page.