thegreenwebfoundation / green-cost-explorer

See how much of your cloud bill is spent on fossil fuels ,so you can do the right thing and switch. We're in a climate crisis, remember?
Apache License 2.0
171 stars 18 forks source link

Include Costs Paid for by Credits #26

Open flowirtz opened 4 years ago

flowirtz commented 4 years ago

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 commented 4 years ago

Hi Flo, thanks for opening the issue.

Does AWS expose these credits to.you I a way to make it possible to count them, or do you just see a final number?

It would be great to see this in, as I don't have any experience with AWS's system of having credits issued against your bill.

Sent from my phone. Please excuse typos and brevity.

On Sat, 15 Aug 2020, 14:46 Flo, notifications@github.com wrote:

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',

  MatchOptions: [

    'EQUALS',

  ],

  Values: [

    'CREDIT', /* Could also be CREDITS, not sure */

  ]

},

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/thegreenwebfoundation/green-cost-explorer/issues/26, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAEL4RGN6WVJCELMR2IKATSAZ7QVANCNFSM4QAIIOGA .

flowirtz commented 4 years ago

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:

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 commented 4 years ago

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.