Skip to content

Instantly share code, notes, and snippets.

@Kerl1310
Created November 3, 2021 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kerl1310/64042f13671ba131f7e0b1391cd8133c to your computer and use it in GitHub Desktop.
Save Kerl1310/64042f13671ba131f7e0b1391cd8133c to your computer and use it in GitHub Desktop.
Uploading emissions metric to CloudWatch
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