Create CloudWatch Alarm and Dashboard

Contents:

Set up CloudWatch Dashboard

Alarm

  • Enter a name in Dashboard name
  • Click Create dashboard

Alarm

  • In the dashboard interface, click the + icon in the top right corner

Alarm

  • In the Add widget interface, set Data source types to CloudWatch
  • Choose MetricsLine
  • Click Next

Alarm

  • In Add metric graph, select ApiGateway → By Stage → choose the metrics you want
  • Click Create widget

Alarm Alarm Alarm

  • If you’re satisfied with your dashboard, click Save

Alarm

Create Alarm

Alarm

  • In Step 1 of Create alarm, select Select metric → ApiGateway → By Stage → choose Count of stage test → Click Select metric

Alarm Alarm

  • In the next interface, set Statistic to Sum, Threshold to Static, and Whenever Count is… Greater Than… 10 (for testing the function)
  • Click Next

Alarm

  • In Step 2, set Alarm state trigger to In alarm
  • Choose Create new topic, give it a name, enter your email, and click Create topic

Alarm

  • Add a Lambda action and select the ForceChangeLimit Lambda
  • Click Next

Alarm

  • In Step 3, name the alarm and click Next

Alarm

  • In Step 4, review and click Create alarm

Alarm

Add Invoke Permission for Alarm

  • Go to the ForceChangeLimit Lambda and click the Configuration tab

Alarm

  • Select Permission → under Resource-based policy statements, click Add permissions

Alarm

  • Set Service to Other
  • Enter StatementID
  • Set Principal to lambda.alarms.cloudwatch.amazonaws.com
  • Source ARN is the ARN of the alarm you just created
  • Actionlambda:InvokeFunction
  • Click Save

If this action is missing, the alarm will not be able to trigger the Lambda function

Alarm

Test Alarm

  • Send requests through Postman that exceed the allowed request limit and check the results. If the notification is sent successfully to Slack and the alarm changes to In Alarm, it means the alarm is working properly.

Alarm