Create CloudWatch Alarm and Dashboard
Contents:
Set up CloudWatch Dashboard

- Enter a name in Dashboard name
- Click Create dashboard

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

- In the Add widget interface, set Data source types to CloudWatch
- Choose Metrics → Line
- Click Next

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

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

Create Alarm

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

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

- 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

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

- In Step 3, name the alarm and click Next

- In Step 4, review and click Create alarm

Add Invoke Permission for Alarm
- Go to the ForceChangeLimit Lambda and click the Configuration tab

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

- 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
- Action → lambda:InvokeFunction
- Click Save
If this action is missing, the alarm will not be able to trigger the Lambda function

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.
