Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Include Costs Paid for by Credits #26

Open
flowirtz opened this issue Aug 15, 2020 · 3 comments
Open

Include Costs Paid for by Credits #26

flowirtz opened this issue Aug 15, 2020 · 3 comments

Comments

@flowirtz
Copy link

flowirtz commented Aug 15, 2020

I just ran this script on our AWS account. This is the result I got:

│ Total Green Cost             │ Total Grey Cost              │
├──────────────────────────────┼──────────────────────────────┤
│ 100.0% ($0.08)               │ 0.0% ($0.00)                 │

Now, that's good, because we run everything in Ireland anyway, but it's bad because we definitely spent more than 8 cents last month.

Our AWS bill is fully covered by credits we got from them. It seems that the script is excluding these costs in the calculation.

I believe that a lot of companies, especially startups, have vast amounts of credits from AWS via their various accelerator programs. I think that these "costs" should be included in the calculation.


After some googling, it seems that CostExplorer.getCostAndUsage supports this via something like:

    Dimensions: {
      Key: 'RECORD_TYPE',
      Values: [
        'Credit',
      ]
    },

I'll try to get a PR up for this.

@mrchrisadams
Copy link
Member

mrchrisadams commented Aug 15, 2020 via email

@flowirtz
Copy link
Author

Hey Chris,

I'm totally new to their Cost Explorer world as well, so not sure I have an answer.

After modifying the request to the cost explorer just now the response I get consists of all negative numbers. This makes sense, as all our cost is covered via Credits.

Here is an example snippet of the response (numbers changed):

{
    "TimePeriod": {
        "Start": "2020-05-01",
        "End": "2020-06-01"
    },
    "Total": {},
    "Groups": [{
        "Keys": ["eu-west-1", "Amazon EC2 Container Service"],
        "Metrics": {
            "BlendedCost": {
                "Amount": "-3.456789",
                "Unit": "USD"
            },
            "UsageQuantity": {
                "Amount": "0",
                "Unit": "N/A"
            }
        }
    }, {
        "Keys": ["eu-west-1", "Amazon Simple Queue Service"],
        "Metrics": {
            "BlendedCost": {
                "Amount": "-4.456789",
                "Unit": "USD"
            },
            "UsageQuantity": {
                "Amount": "0",
                "Unit": "N/A"
            }
        }
    }, {
        "Keys": ["eu-west-1", "Amazon Simple Storage Service"],
        "Metrics": {
            "BlendedCost": {
                "Amount": "-0.456789",
                "Unit": "USD"
            },
            "UsageQuantity": {
                "Amount": "0",
                "Unit": "N/A"
            }
        }
    }, {
        "Keys": ["eu-west-2", "Amazon Simple Queue Service"],
        "Metrics": {
            "BlendedCost": {
                "Amount": "0",
                "Unit": "USD"
            },
            "UsageQuantity": {
                "Amount": "0",
                "Unit": "N/A"
            }
        }
    }, {
        "Keys": ["global", "AWS Budgets"],
        "Metrics": {
            "BlendedCost": {
                "Amount": "-0.01",
                "Unit": "USD"
            },
            "UsageQuantity": {
                "Amount": "0",
                "Unit": "N/A"
            }
        }
    }, {
        "Keys": ["us-east-1", "Amazon Simple Storage Service"],
        "Metrics": {
            "BlendedCost": {
                "Amount": "-0.000345",
                "Unit": "USD"
            },
            "UsageQuantity": {
                "Amount": "0",
                "Unit": "N/A"
            }
        }
    }],
    "Estimated": false
}

The script works fine with that and gives me the following output (looks about right):

┌──────────────────────────────┬──────────────────────────────┐
│ Total Green Cost             │ Total Grey Cost              │
├──────────────────────────────┼──────────────────────────────┤
│ 99.6% ($-123.45)             │ 0.4% ($-1.23)                │
└──────────────────────────────┴──────────────────────────────┘

I think there are three cases we need to cover:

  • cost wholly covered by credits: works (see above)
  • cost wholly covered by cash: think it should work, can't check though, don't have access to a paying AWS account rn
  • cost blended between cash/credits: I think this would produce faulty results, as the cost is summed, effectively subtracting the credits again

I'll propose a draft PR for this and then somebody else could try running this on their paying AWS account or I'll try to incur a small charge (if there is such a thing with AWS...) on my private account to test this.

@mrchrisadams
Copy link
Member

hey @flowirtz - I think the sample data in data has figures that were purely covered by a payment, rather than there being credits. I ran it against some number in my personal account to generate them. Is that sufficient for you?

I'll ask around for someone who does have a mix of credits / cash in a bill.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants