Lambda Python function unable to write to CloudWatch

Viewed 94

I am trying to push some custom sample metrics to Cloudwatch from a lambda function using the code below, but it times out, even with a timeout limit of 30 seconds. Just to be sure, I set full CloudWatch permissions to the lambda function, but to no avail. Any ideas what could cause this?

import boto3
import random
def lambda_handler(event, context):
    cloudwatch = boto3.client('cloudwatch')
    cloudwatch.put_metric_data(
        MetricData = [
            {
                'MetricName': 'KPIs',
                'Dimensions': [
                    {
                        'Name': 'PURCHASES_SERVICE',
                        'Value': 'CoolService'
                    },
                    {
                        'Name': 'APP_VERSION',
                        'Value': '1.0'
                    },
                ],
                'Unit': 'None',
                'Value': random.randint(1, 500)
            },
        ],
        Namespace = 'TestMetrics'
    )
0 Answers
Related