冷呆獸試驗場

Get Estimated Charge of AWS account

使用AWS帳號時,通常都是到每個月的三、四日時會對前一個月份的費用自動扣款及收到invoice,有沒有辦法更早知道前一個月份的費用金額呢?AWS很體貼的提供了一個方便的功能,就是CloudWatch的預設metric "EstimatedCharges"

以下說明自己在處理這個部份的一些經驗和步驟:

Steps:

  1. In IAM, Create a account with CloudWatch Read Only permission. Download its credential (AccessKey and SecretKey)
  2. Install Amazon CloudWatch Command Line Tool
  3. The time of Lastest value of metric EstimatedCharges differs from the Real time in GMT+8 is about 14 hours ( include 8 hours timezone difference ). Additional 6 hours should be buffered by AWS.
  4. After determined the time of record we should get from CloudWatch, use following command to get value:

    mon-get-stats EstimatedCharges --statistics "Maximum" --start-time "2014-08-25T22:00:00Z" --namespace "AWS/Billing" --dimensions "Currency=USD" -I [AccessKey] -S [SecretKey] --region us-east-1
    
  5. Then you should get the amount of charges ( the metric "EstimatedCharges" includes all charges of AWS ).

  6. You can use some script language to automate this action and put it to some scheduled jobs like crontabs.

Note:

  1. The region can only be set to "us-east-1".
  2. Sometimes you will get empty output, please review the start time and retry.
  3. There are some other metrics like EstimatedCharges, please notice the namespace.