AWSAmazon EC2Compute

aws_instance cost estimation

An EC2 virtual machine. Priced per hour by instance type, OS, tenancy, and region, with separate charges for attached EBS volumes and data transfer.

An aws_instance provisions one EC2 virtual machine. The bulk of the cost is the per-hour rate for the instance itself, which depends on the instance type (size of CPU, memory, networking), operating system (Linux is cheapest, RHEL and Windows add a license surcharge), tenancy (shared is cheapest, dedicated and host are premium), and region. EC2 instance hours are billed by the second with a one-minute minimum.

On top of the instance hour rate, an EC2 instance has two other meaningful cost dimensions. First, the root EBS volume and any attached EBS volumes (aws_ebs_volume or ebs_block_device) are billed separately per GB-month, with the rate depending on the volume type (gp3 is the modern default and usually cheapest). Second, data transferred out of the AWS region incurs separate egress charges, which can dominate the bill for high-throughput workloads.

c3x estimates all three of these from the Terraform configuration. Instance hours assume 730 hours per month (continuous running). EBS volume costs use the provisioned size, not the actual used bytes. Data transfer costs are usage-based and require a c3x-usage.yml file to model accurately.

Terraform example

A minimal but realistic configuration that C3X can estimate.

resource "aws_instance" "api" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "m5.xlarge"

  root_block_device {
    volume_type = "gp3"
    volume_size = 100
  }

  ebs_block_device {
    device_name = "/dev/sdf"
    volume_type = "gp3"
    volume_size = 500
  }

  tags = {
    Name = "api-server"
  }
}

Pricing dimensions

What you actually pay for when you provision aws_instance.

DimensionUnitWhat's being charged
Instance hoursper hourOn-demand rate for the instance type, charged for every hour the instance is running. c3x assumes 730 hours per month for monthly estimates.
$0.192/hour for m5.xlarge Linux in us-east-1
Root block deviceper GB-monthProvisioned size of the root EBS volume. Billed even when the instance is stopped.
$0.08/GB-month for gp3 in us-east-1
Attached EBS volumesper GB-monthSame per-GB rate as the root volume. Snapshots are billed separately by aws_ebs_snapshot.
Provisioned IOPS (io1/io2/gp3 above baseline)per IOPS-monthFor io1/io2 volumes or gp3 volumes provisioned above 3,000 baseline IOPS.
Data transfer outper GBBytes egressing the AWS region to the internet. First 100 GB/month free at the account level. Define expected volume in c3x-usage.yml for an accurate estimate.
$0.09/GB for first 10 TB out to internet

Sample C3X output

Example output from c3x estimate on the Terraform above:

aws_instance.api
├─ Instance usage (Linux/UNIX, on-demand, m5.xlarge)    730  hours      $140.16
├─ root_block_device
│  └─ Storage (general purpose SSD, gp3)                100  GB           $8.00
└─ ebs_block_device[0]
   └─ Storage (general purpose SSD, gp3)                500  GB          $40.00

OVERALL TOTAL                                                           $188.16

Optimization tips

Common ways to reduce aws_instance cost without changing the workload.

Move from m5 to m7i for the same workload

Up to 15%

The m7i family delivers ~15% better price-performance than m5 in equivalent sizes. The hourly rate is similar; the gain comes from finishing work faster, so total instance-hours drop.

Switch root and data volumes from gp2 to gp3

About 20%

gp3 is roughly 20% cheaper than gp2 at the same size and gives 3,000 baseline IOPS by default (vs gp2's size-dependent IOPS). For most workloads, gp3 is a strict upgrade.

Consider Savings Plans for steady-state instances

30-40%

A 1-year Compute Savings Plan typically cuts on-demand rates by 30-40% with no instance-type commitment. Define purchaseOption: 'savings_plan' in c3x-usage.yml to model this.

Right-size by looking at actual CloudWatch utilization

30-50%

EC2 instances are often provisioned 2-4x larger than needed. Pull average and p99 CPU/memory from CloudWatch and downshift one or two sizes if usage stays below 40%.

FAQ

How does c3x estimate EC2 instance costs?

c3x reads the instance_type, ami (to detect OS), tenancy, and region from your Terraform configuration, then looks up the on-demand hourly rate from the AWS Pricing API. It multiplies by 730 hours per month for the monthly estimate. EBS volumes, IOPS, and data transfer are estimated separately.

Does c3x handle Reserved Instances and Savings Plans?

Yes. Add purchaseOption: 'reserved' or 'savings_plan' under the resource in c3x-usage.yml with the term length and offering class. c3x will apply the discounted rate to the monthly estimate.

Why is my EBS volume showing as a separate line item?

EBS volumes are billed separately from instance hours, even when defined inline with root_block_device or ebs_block_device. c3x mirrors this in the output to make it obvious which sub-resource is driving the cost.

Does c3x include data transfer in EC2 cost estimates?

Only if you specify expected egress in a c3x-usage.yml file. Without that, data transfer is a usage-based dimension that defaults to zero and is marked as such in the output.

Can c3x estimate Spot instance costs?

Spot pricing is dynamic and unpredictable. c3x can model Spot if you set purchaseOption: 'spot' in the usage file, using the AWS Spot price advisor's recent average. Treat the result as a rough guide, not a contract.

Related resources

Estimate this resource in your own Terraform

Free, open source, no API key. C3X parses your Terraform and shows line-item cost for every resource, including aws_instance.