Interview Prep/Python for DevOps/AWS automation with boto3

Finance asks why EC2 spend doubled last month. You have Python and read access. What do you do?

IntermediateScenarioAWS automation with boto3
Answer

Situation read → Cost investigation; the data is in Cost Explorer, not EC2.

What I'd do →

  1. Query Cost Explorer: ce.get_cost_and_usage(TimePeriod=..., Granularity="DAILY", Metrics=["UnblendedCost"], GroupBy=[{"Type": "DIMENSION", "Key": "USAGE_TYPE"}]) to see when and which usage type jumped.
  2. Group by LINKED_ACCOUNT, REGION, INSTANCE_TYPE and by the Owner tag to narrow it.
  3. Cross-check with CloudTrail RunInstances events around the day of the jump.
  4. Report with a daily chart and the specific resources.

Why → Start from billing data and drill down; do not guess from current inventory.

Interview tip → Note that Cost Explorer API calls cost $0.01 each, so cache results.

All Python for DevOps questions Roadmap: Python for automation

More on AWS automation with boto3