Khue Nguyen
Khue Nguyen

Reputation: 113

Use Lambda function to read a certain Cloudwatch alarm status and its metrics with Python

I'm completely new with boto. I created a Cloudwatch alarm for a certain Kinesis metrics. Now I want to write a Lambda function which can read the alarm status and the corresponding metrics value in every 5 minutes.

Does anyone have experiences with this task and can help me?

following is what I'm currently having in my code:

import json
import boto3

def lambda_handler(event, context):
    cloudwatch = boto3.resource('cloudwatch')
    alarm = cloudwatch.Alarm('Test') 
    response = alarm.describe_alarms()
    return{reponse}

Thanks a lot

Upvotes: 0

Views: 1359

Answers (1)

Marcin
Marcin

Reputation: 238199

There are several ways of doing this. One would be:

  1. Add/modify execution role of your function with permissions to read CloudWatch metrics.

  2. Use boto3's cloudwatch to read the metrics you require. You already started doing this.

  3. Setup a CloudWatch Event scheduled rule to trigger your lambda function every 5 minutes.

Upvotes: 1

Related Questions