I think I donât need to remind you that climate change is a big deal and that humanity must urgently reduce its CO2 emissions.
We, web developers, must do our part: It has been estimated data centers produce 2% of the global greenhouse gases emissions.
To help us take data-driven actions, cloud providers have started building monitoring dashboards of our cloud usage carbon emissions:
- Microsoft released the Emissions Impact Dashboard in 2020
- Google released the Carbon Footprint service on GCP in 2021
- And AWS just released their Customer Carbon Footprint Tool last month (feb. 2022)
At Kumo, we develop Serverless applications (which, by the way, seem to be inherently greener...). So this article will focus on AWS, which has always been ahead regarding Serverless.
The sad thing is that AWS have been quite late regarding CO2 emissions monitoring: Their Customer Carbon Footprint Tool has just been just released (2 years after Azure), and, for now, suffers from strong limitations:
- Results have high granularity (100 kgCO2 equivalent versus 1 for GCPâs Carbon Footprint)
- Only the S3 and EC2 services are available in the emissions breakdown by service : In the case of a Serverless application, most of the emissions will fall... in the âOtherâ category
So weâve searched for alternatives, and found Cloud Carbon Footprint đ
Cloud Carbon Footprint is an open-source application that enables projects to monitor their cloud usage CO2 emissions on GCP, Azure... and AWS! It also offer nice features like breakdowns by region, account or AWS service:
Feel free to test the online demo for more details!
The emissions are derived from billing. The billing-to-CO2 coefficients are debated by the Cloud Carbon Footprint community (and overridable if needed). You can find more infos on the project methodology page, and contribute to their Github project or Google Group.
This article explains how set up Cloud Carbon Footprint on your project in only a few clicks, so you can start taking actions now! Letâs dive in đ
đ Create a Cost & Usage Reports
Before setting Cloud Carbon Footprint up, letâs take a quick look at how it works.
Technically, Cloud Carbon Footprint uses Athena to run queries on a S3 containing the data of Cost & Usage Reports made by AWS Billing. Itâs a mouthful, so letâs draw it:
One consequence is that you cannot install Cloud Carbon Footprint and have it work out-of-the-box: Youâll have to do some setup in your AWS account first.
Setting up all those resources by hand can be quite long... Thankfully, you wonât have to do it, because we made a CloudFormation template just for you â€ïž
To use it:
- Download the JSON template from my Github repository
- Open the Cloudformation service in the us-east-1 region (weâll see why later)
- Select Create stack > With new resources and Template is ready
- Select Upload a template file, upload the JSON template and select Next
- Choose a stack name (like cloud-carbon-footprint) and select Next until you reach the âReviewâ page
- In the âReviewâ page, accept the check boxes and select Create stack
And voilĂ ! For the curious, this template will deploy:
- đȘŁ A S3 Bucket and a S3 Bucket Policy to store the Cost & Usage Report (âBillingDataBucketâ)
- đ The Cost & Usage Report definition (âCurDefinitionâ)
- đââïž The necessary Glue, Lambda and IAM resources to allow Athena to crawl the Cost & Usage Report
- đȘŁ A S3 bucket to store Athena query results (âAthenaQueryResultsBucketâ)
- đ The necessary IAM resources to allow Cloud Carbon Footprint to perform said queries (âCloudCarbonFootprintUserPolicyâ and âCloudCarbonFootprintUserâ)
Two important notes:
- It is important to base this stack in the us-east-1 region as the AWS::CUR::ReportDefinition resource type is only available there (donât worry, reports are still cross-regions)
- If your account is not the paying account (like a linked account in AWS Organization), the paying account should enable Cost & Usage Reports first in the AWS Billing Console
Once the required resources are deployed, simply wait: It can take up to 24h for AWS Billing to create the first Cost & Usage Report.
đ Launch Cloud Carbon Footprint
Once a first Cost & Usage Report is available (it will be visible in the AWS Billing Console > check the âData last refreshedâ column), you are ready to launch Cloud Carbon Footprint!
- Open the IAM Console and select Create Access Key on the cloud-carbon-footprint user: Write down the Access key ID and the Secret access key (you will only see the latter once)
- If you havenât done it, install the AWS CLI
- Configure a new profile and set it as your default user
aws configure --profile <PROFILE_NAME>
# AWS Access Key ID: <ACCESS_KEY_ID>
# AWS Secret Access Key: <SECRET_ACCESS_KEY>
# Default region name: Your default region (ex: eu-west-1)
# Default output format: Your default output format (ex: json)
export AWS_PROFILE=<PROFILE_NAME>
- Install the cloud-carbon-footprint package via npx
npx @cloud-carbon-footprint/create-app
# Submit your PROJECT_NAME in the wizard
cd <PROJECT_NAME>
yarn install
yarn guided-install
# Cloud provider: AWS
# AWS account id: <YOUR_PROJECT_ACCOUNT_ID> (e.g. 628019955336)
# AWS account name: <YOUR_PROJECT_NAME> (e.g. "[PRODUCTION] Master Account")
# AWS region: us-east-1 (should be the region of the CUR bucket)
# Ensure your AWS account has the correct permission: Yes
# AWS role name: <ANY_VALUE> (doesn't work)
# Enable the Cost and Usage Reports Billing AWS feature: Yes
# Setup Athena DB to save the Cost and Usage Reports: Yes
# Athena DB name: costandusagereportdatabase
# Athena DB table: costandusagereport
# Athena DB query result location: s3://<STACK_NAME>-athenaqueryresultsbucket-<SOME_HASH>
# (can be found in the s3 service)
# Install the AWS CLI: Yes
# Configure aws credentials locally: No
# Run `aws configure`: Yes
yarn start
- And voilĂ ! You should have your dashboard ready to go đ
The data will go back up to the oldest data available in the Cost and Usage Report, which should be the beginning of its creation month, and will be refreshed at least daily. It is important not to remove the Report as long as you want to monitor your emissions.
Now you can start taking actions in favor of climate đȘ
Cheers!
Top comments (0)