AWS Resource Cost Step: Accurate Cost Analysis for AWS Resources

Modified on Tue, 28 Jan, 2025 at 5:07 PM

The AWS Resource Cost step is designed to help customers retrieve accurate cost information for specific AWS resources. This powerful feature allows for efficient and precise cost analysis, crucial for effective FinOps practices.

 

How It Works


  1. Select the AWS Service: 

    • Choose the specific AWS service for your resource(s)

    • This selection helps optimize the query efficiency

  2.  Specify the Pricing Model:

    • Choose between:

      • General services (rate not impacted by the number of days in the month)

      • Storage services like EBS/S3 (rate is GB-Month)

  3. Cost Calculation:

    • The step calculates the daily cost for the previous 4 days

    • This approach accounts for potential delays in the Cost and Usage Report (CUR) updates

  4. Select Cost Type:

    • Choose from:

      • Unblended - The actual AWS usage charge for the hour, day, or month without any averaging or spreading of Reserved Instance or Savings Plan costs

      • Amortized - The AWS costs evenly distributed across the billing period, typically showing how Reserved Instance and Savings Plan upfront payments are spread over their term

      • Net Unblended - The raw AWS usage charges minus any applied credits, refunds, or discounts for that specific billing period

      • Net Amortized - The spread-out AWS costs (including distributed RI and SP costs) after subtracting any credits, refunds, or discounts

  5. Exclusions (Highly Recommended):

    • Option to exclude:

      • Tax - A mandatory charge added to AWS services based on your location and local tax regulations

      • Discounts - Reductions in AWS pricing through programs like Enterprise Discount Program (EDP) or volume-based pricing tiers

      • Credits - AWS-provided funds (like promotional or support credits) that can be automatically applied to offset future AWS service charges

      • Refunds - Money returned to your payment method for AWS service issues, billing errors, or unused Reserved Instance time

 

Important Considerations

❗Query Cost
Running this query can incur a cost of data scanning. From our checks, the cost is usually a few cents, and on a huge account($10M Monthly Spend), it can be up to 20 cents. You should be aware of this when checking resource costs
We highly recommend running one query for all resources you need to analyze 
To optimize costs and efficiency, batch your resource queries when possibl


Resource Ids
You can query single or multiple resources using the same format:
['resource_id1','resource_id2']

The resource ID is usually the resource ARN, but in some cases (like EC2 and EBS for example) just use the resource id.

 

Cost Calculation Methodology

The system calculates projected costs using the following methodology:

  • The process begins by retrieving daily cost data from 4 days prior, accounting for potential delays in Cost and Usage Report (CUR) updates
  • This single day's cost serves as the baseline for all cost projections
  • Monthly costs are calculated by multiplying the daily cost by the number of days in the current month
  • Annual cost projections are determined by multiplying the daily cost by 365 days

This standardized approach ensures consistent and reliable cost estimation across the platform.

 


The Query Behind the Calculations

To give you a deeper understanding of how costs are calculated, here's an example of the query used (in this case, for EC2 storage):

WITH sample_day AS (
    SELECT date(current_date - INTERVAL '4' DAY) AS sample_date
),
daily_costs AS (
    SELECT 
        line_item_resource_id AS resource_id,
        SUM(line_item_unblended_cost) AS daily_cost
    FROM wivdb.wiv_cur
    WHERE line_item_product_code = 'AmazonEC2'
        AND product_product_family = 'Storage'
        AND date(line_item_usage_start_date) = (SELECT sample_date FROM sample_day)
        AND line_item_line_item_type NOT IN ('Credit', 'Discount')
        AND line_item_resource_id IN ('vol-0822aff77ebb7e1dd')
    GROUP BY line_item_resource_id
),
days_in_month AS (
    SELECT EXTRACT(DAY FROM DATE_ADD('day', -1, DATE_ADD('month', 1, DATE_TRUNC('month', current_date)))) AS days_in_month
)
SELECT 
    resource_id,
    ROUND(daily_cost * (SELECT days_in_month FROM days_in_month), 2) AS projected_monthly_cost,
    ROUND(daily_cost * 365, 2) AS projected_annual_cost
FROM daily_costs;

 

This query:

  1. Determines the sample date (4 days ago)

  2. Calculates the daily cost for specified resources

  3. Determines the number of days in the current month

  4. Projects monthly and annual costs based on the daily cost

Note that this query is an example and may vary based on the specific AWS service and cost type selected.

 

Edge Case: New, Stopped, or Short-lived Resources

It's important to note that cost calculations may be inaccurate in certain scenarios:

  • If the resource didn't exist 4 days ago

  • If the resource wasn't running for a full 24 hours in the past 4 days

  • Stopped resources identified in the CLI response that have not generated any associated costs

This limitation is part of the challenge in calculating costs from the CUR, especially when trying to determine accurate Amortized and Net Amortized costs. Keep this in mind when analyzing costs for newly created or intermittently running resources.

 

Example Usage

Let's say you want to get the cost for two EC2 instances:

  1. Select "EC2" as the AWS Service

  2. Choose "General services" for the pricing model

  3. Select your preferred cost type (e.g., "Amortized")

  4. Exclude Tax, Credits, and Refunds

  5. Input the resource IDs: ['i-1234567890abcdef0','i-0987654321fedcba0']

 

This will give you the daily amortized cost for these two EC2 instances, excluding tax, credits, and refunds. 



Summary

By leveraging the AWS Resource Cost step effectively, you can gain precise insights into your AWS spending, enabling better cost optimization and resource management in your FinOps workflows.





Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article