Created
November 3, 2021 12:17
-
-
Save Kerl1310/64042f13671ba131f7e0b1391cd8133c to your computer and use it in GitHub Desktop.
Uploading emissions metric to CloudWatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decimal import Decimal | |
import boto3 | |
cloudwatch_client = boto3.client('cloudwatch', 'eu-west-2') | |
def upload_emissions_to_cloudwatch(value, timestamp): | |
''' | |
Uploads emissions custom metric to CloudWatch | |
''' | |
return cloudwatch_client.put_metric_data( | |
Namespace='EmissionsDemo', | |
MetricData=[ | |
{ | |
'MetricName': 'co2_emissions_in_kg', | |
'Value': Decimal(value), | |
'Unit': 'None', | |
'Timestamp': timestamp | |
} | |
] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment