Skip to content

feat(events): add CloudWatchAlarmEvent for Lambda alarm actions - #653

Open
nakultt wants to merge 1 commit into
aws:mainfrom
nakultt:events/cloudwatch-alarm-lambda-event
Open

nakultt wants to merge 1 commit into
aws:mainfrom
nakultt:events/cloudwatch-alarm-lambda-event

Conversation

@nakultt

@nakultt nakultt commented Oct 28, 2026 •

Copy link
Copy Markdown

Issue #, if available: #555

Description of changes:

Adds events.CloudWatchAlarmEvent, the payload CloudWatch sends when a Lambda function is configured directly as an alarm action (docs). The existing CloudWatchAlarmSNSPayload only covers the SNS-delivered format.

  • Metric alarms: configuration.metrics with metricStat (namespace, name, dimensions, period, stat, unit) and returnData
  • Composite alarms: alarmRule, actionsSuppressor, wait/extension periods, and actionsSuppressedBy/actionsSuppressedReason on the state
  • Alarm tags: alarmTags and alarmTagsStatus

Notes:

  • Timestamps are kept as string because CloudWatch uses a +0000 offset (e.g. 2023-08-04T12:36:15.490+0000) that time.Time can't unmarshal. This matches CloudWatchAlarmSNSPayload.StateChangeTime.
  • reasonData stays a JSON-encoded string, as delivered by CloudWatch.
  • Types use a CloudWatchAlarm prefix to avoid clashing with the SNS payload types (CloudWatchMetric, CloudWatchMetricStat, ...), which use PascalCase JSON keys.
  • Log-alarm configuration fields aren't modelled yet; those events still unmarshal (extra fields are ignored). Happy to add them here or in a follow-up.

Testing: the fixtures are the documented metric and composite alarm example events. The tests round-trip both through json.Unmarshal/json.Marshal and check key fields, plus the malformed-JSON check.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov-commenter

codecov-commenter commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.04%. Comparing base (4111853) to head (d9e337c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #653   +/-   ##
=======================================
  Coverage   82.04%   82.04%           
=======================================
  Files          37       37           
  Lines        1487     1487           
=======================================
  Hits         1220     1220           
  Misses        264      264           
  Partials        3        3           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add the event type CloudWatch sends when a Lambda function is configured
directly as an alarm action. Covers metric alarms, composite alarms, and
alarm tags. Timestamps are strings because CloudWatch uses a +0000 offset
that time.Time cannot parse, matching CloudWatchAlarmSNSPayload.

Fixes aws#555
@nakultt
nakultt force-pushed the events/cloudwatch-alarm-lambda-event branch from 8c2ae73 to d9e337c Compare October 28, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants