Skip to main content

AWS Lambda & CloudWatch Alarms Testing

Invoke Lambda Function Locally

aws lambda invoke \
  --function-name CloudWatch-Alarms-To-Slack \
  --cli-binary-format raw-in-base64-out \
  --payload file://test-event.json \
  --region ap-south-1 \
  /tmp/lambda-test-output.json

Tail Lambda Logs

aws logs tail /aws/lambda/CloudWatch-Alarms-To-Slack --since 5m --format short

Publish Test Message to SNS Topic

aws sns publish \
  --topic-arn arn:aws:sns:ap-south-1:3AWS-Account-ID-NO5:PROD_Default_CloudWatch_Alarms_Topic \
  --subject "TEST: CloudWatch Alarm Notification" \
  --message '{
    "AlarmName": "TEST-SNS-CloudWatch-Alarm",
    "AlarmDescription": "Testing SNS to Lambda integration",
    "AWSAccountId": "3AWS-Account-ID-NO5",
    "NewStateValue": "ALARM",
    "NewStateReason": "Testing SNS topic can trigger Lambda function",
    "StateChangeTime": "2026-01-12T13:30:00.000Z",
    "Region": "ap-south-1",
    "AlarmArn": "arn:aws:cloudwatch:ap-south-1:3AWS-Account-ID-NO5:alarm:TEST-SNS-CloudWatch-Alarm",
    "OldStateValue": "OK",
    "Trigger": {
      "MetricName": "CPUUtilization",
      "Namespace": "AWS/RDS",
      "StatisticType": "Statistic",
      "Statistic": "Average",
      "Dimensions": [
        {
          "name": "DBInstanceIdentifier",
          "value": "test-rds-instance"
        }
      ],
      "Period": 300,
      "EvaluationPeriods": 3,
      "ComparisonOperator": "GreaterThanThreshold",
      "Threshold": 80.0
    }
  }' \
  --region ap-south-1