Skip to main content

Testing CloudWatch Alarm β†’ SNS β†’ Lambda β†’ Slack Pipeline

πŸ§ͺ Testing Methods (From Safest to Most Realistic)


Method 1: Direct Lambda Test (Already Done βœ…)

What it tests: Lambda function only
Risk: Zero
Time: Instant
Result: βœ… Already verified working
What it tests: SNS β†’ Lambda integration
Risk: Zero
Time: Instant

Step 1: Verify SNS subscription is confirmed

Expected Output:

Step 2: Publish a test message to SNS

Expected Output:

Step 3: Verify Lambda was invoked


Method 3: Manually Trigger an Alarm State (Safe 🟒)

What it tests: CloudWatch β†’ SNS β†’ Lambda β†’ Slack (full pipeline)
Risk: Low (just changes alarm state, doesn’t affect resources)
Time: Instant

Option A: Use a test alarm (if you have one)

Option B: Create a temporary test alarm


Method 4: Wait for Real Alarm (Production Test πŸ”΄)

What it tests: Everything in real production scenario
Risk: None (passive monitoring)
Time: Variable (when an actual alarm triggers)
Just wait for one of your 40 existing alarms to trigger naturally. This is the ultimate test but requires patience.

Method 5: Temporarily Lower Threshold (Controlled Test 🟑)

What it tests: Real CloudWatch alarm with actual metrics
Risk: Medium (might cause unnecessary alerts)
Time: 5-15 minutes

Example: Test CPU alarm with lower threshold

⚠️ Warning: This will cause a real alarm to trigger. Use with caution!

Method 6: CloudWatch Logs Insights (Verification)

What it tests: Check if Lambda is being invoked by SNS
Risk: Zero
Time: Instant

For Initial Testing (Do this now):

For Full End-to-End Testing (Optional):


πŸ“Š What to Look For in Each Test

In Slack:

In Lambda Logs:

In SNS Metrics:


πŸ” Troubleshooting

Problem: SNS test doesn’t trigger Lambda

Check:

Problem: Alarm test doesn’t trigger

Check:

βœ… Quick Test Script

Save this as test-slack-integration.sh:
Run it:

πŸ“‹ Test Checklist

  • Lambda function tested directly βœ… (Already done)
  • SNS subscription confirmed as β€œConfirmed” status
  • SNS β†’ Lambda test passed (Method 2)
  • Test alarm created and triggered (Method 3)
  • Slack message received
  • Lambda logs show successful execution
  • CloudWatch metrics show SNS deliveries
  • End-to-end pipeline verified

🎯 Summary

Best practice for testing:
  1. βœ… Already tested: Direct Lambda invocation
  2. 🟒 Do now: SNS publish test (Method 2)
  3. 🟑 Optional: Create temporary test alarm (Method 3)
  4. πŸ”΅ Wait: Real alarm will eventually trigger naturally
The SNS publish test (Method 2) is the sweet spot - it’s:
  • Safe (no risk to production)
  • Fast (instant results)
  • Comprehensive (tests SNS β†’ Lambda β†’ Slack)
  • Realistic (uses same path as real alarms)
Run this now to verify everything works: