aws-samples / aws-cudos-framework-deployment

Command Line Interface tool for Cloud Intelligence Dashboards deployment
https://catalog.workshops.aws/awscid
MIT No Attribution
400 stars 157 forks source link

EC2 unblended cost substantially off value returned from Athena query of same data #860

Closed work-bw closed 3 months ago

work-bw commented 3 months ago

If I create a table with resource_view:

Group by:
service
account_name
Value:
unblended_cost (Sum)
Filter:
usage_date= previous month
account_id= <my account id>
service= Filter list - include AmazonEC2

I get an unblended_cost of 5844.26

However, when I run this Athena query:

SELECT SUM(line_item_blended_cost) AS cost
FROM "cid_cur"."cur" WHERE
line_item_usage_account_id= '<my account id>' and
product_servicecode = 'AmazonEC2' and
line_item_usage_start_date >= timestamp '2024-05-01 00:00:00.000' and
line_item_usage_end_date < timestamp '2024-06-01'
;

I get cost= 3426.1666624877084

It is not close and as far as I can tell I'm using the same data. I've reached out to my TAM but the Cost Intelligence team is more likely to understand the issue and offer ideas on how to fix or know if it their issue. Other services like S3 and VPC show correct unblended_cost numbers or pretty darn close to what I'm billed by AWS. Please help. Thank you.

work-bw commented 3 months ago

I didn't include my account Id in my post. I tried to use <my account id> but it was gobbled by the editor.

iakov-aws commented 3 months ago

Most likely what you get in summary view do not include your discounts. product_servicecode != service (not allways) as discount fields contain product_name and not service code.

try to add a group by line_item_line_item_type (=charge_type in summary view) most likely you will see discounts that are missed

If this will not clarify, please contact your AWS TAM to organize a deepdive session

iakov-aws commented 3 months ago

Also please check that you are comparing line_item_blended_cost with unblended_cost

please use unblended_cost to compare

work-bw commented 3 months ago

Thanks. You are correct. charge_type in resource_view included SavingsPlanCoveredUsage and Usage. If I filtered charge_type to only include Usage I get the correct amount I see on my bill.

In the Athena query adding:

GROUP BY line_item_line_item_type

revealed the discount too.