Skip to content

RFC: Log Alarm L2 Construct - #962

Merged
mergify[bot] merged 3 commits into
aws:mainfrom
rodrigotuna:logalarm-l2
Aug 31, 2026
Merged

mergify[bot] merged 3 commits into
aws:mainfrom
rodrigotuna:logalarm-l2

Conversation

@rodrigotuna

Copy link
Copy Markdown
Contributor

Tracking issue: #960

This RFC proposes a new LogAlarm L2 construct in aws-cdk-lib/aws-cloudwatch, wrapping the AWS::CloudWatch::LogAlarm CloudFormation resource. It follows the accepted PromQLAlarm precedent (extends AlarmBase, reuses existing enums, interchangeable via IAlarm).

A proof-of-concept construct with unit tests and an integration test has been implemented and deployed against a real account, confirming it creates a valid AWS::CloudWatch::LogAlarm.

See text/0960-logalarm-l2.md.

Comment thread text/0960-logalarm-l2.md
a scheduled Logs query (a query string + aggregation over one or more log groups) and compares the aggregated result
against a threshold using an M-out-of-N evaluation. It also can surface matching log lines in the alarm notification.
The construct wraps the `AWS::CloudWatch::LogAlarm` CloudFormation resource, reuses the existing
`ComparisonOperator`/`TreatMissingData` enums, and — like `Alarm` and `PromQLAlarm` — extends `AlarmBase` so it is

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that ComparisonOperator we use for log alarm doesn't support LessThanLowerOrGreaterThanUpperThreshold | LessThanLowerThreshold | GreaterThanUpperThreshold being supported under Metric Alarm. These operations are supported for anomaly detection metric alarm and it is not supported for log alarm.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can still use this enum and validate the parameter at synth. ( Probably, PromQL should also be doing the similar thing if they are reusing the enum ?)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you already covered below:

comparisonOperator must be a static-threshold operator (anomaly-detection operators rejected).

Comment thread text/0960-logalarm-l2.md Outdated
## Summary

`LogAlarm` lets customers alarm directly on logs. Instead of a metric + threshold + evaluation periods, a log alarm runs
a scheduled Logs query (a query string + aggregation over one or more log groups) and compares the aggregated result

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Logs insight query

Comment thread text/0960-logalarm-l2.md Outdated
logGroupIdentifiers: [logGroup.logGroupName],
scheduledQueryRole: queryRole,
schedule: {
frequency: Duration.minutes(5),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should we just name it as rate to align it with scheduled expression rate expression naming ?

Comment thread text/0960-logalarm-l2.md
import { Duration } from 'aws-cdk-lib';

declare const logGroup: logs.LogGroup;
declare const queryRole: iam.IRole;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we see if SQ ( as in GA) supports anything to help the role creation ? If so, customers can use that to simplify the role creationrather than having their own code to create one.

If there is one, we can also replicate the similar thing for log line role as well.

Comment thread text/0960-logalarm-l2.md
declare const logAlarm: cloudwatch.LogAlarm;
declare const topic: sns.Topic;

logAlarm.addAlarmAction(new cloudwatch_actions.SnsAction(topic));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if we can add validation on supported actions for log alarm as well on synth ?

Comment thread text/0960-logalarm-l2.md Outdated
### Are there any open issues that need to be addressed later?

- Alignment of `ScheduledQueryConfiguration` field constraints across the Coral model, CFN schema, and Hermes validation
(tracked in EVENTS-4979): `LogGroupIdentifiers` required→optional, `StartTimeOffset` range `[1, 2592000]`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just publish this with updated schema given we have already started the deployments? Or we plan to update it once we complete all deployments?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, curious if these validations will be done at L1 construct based on CFN schema being published ?

Comment thread text/0960-logalarm-l2.md
Comment thread text/0960-logalarm-l2.md
readonly treatMissingData?: TreatMissingData; // @default - service default
readonly actionLogLineCount?: number; // 0–50; requires role when > 0
readonly actionLogLineRole?: IRole;
readonly alarmActions?: IAlarmAction[];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have default values for these as well or we can mark default none ? We can follow what is being followed for metric alarm. Same goes for other optional parameters like actionLogLineRole

Comment thread text/0960-logalarm-l2.md
Comment thread text/0960-logalarm-l2.md Outdated
Comment thread text/0960-logalarm-l2.md
readonly actionsEnabled?: boolean; // @default true
readonly treatMissingData?: TreatMissingData; // @default - service default
readonly actionLogLineCount?: number; // 0–50
readonly actionLogLineRole?: IRole; // auto-created (trusts cloudwatch.amazonaws.com) when count > 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean auto created only when not passed ? Also, we plan to auto create it , would we have all required parameters in place to auto create it ? Let's also see what further reviewer has take on this.

Comment thread text/0960-logalarm-l2.md Outdated

### Why should we _not_ do this?

There is no strong reason not to. The `ScheduledQueryConfiguration` field constraints are final (`logGroupIdentifiers`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to mention this now given we are going with what will be the final spec?

The ScheduledQueryConfiguration field constraints are final (logGroupIdentifiers
is optional, and the startTimeOffset range is fixed), and the construct tracks the published
@aws-cdk/aws-service-spec

Comment thread text/0960-logalarm-l2.md Outdated

### Are there any open issues that need to be addressed later?

- None. The `ScheduledQueryConfiguration` field constraints are final; the L2 tracks the published

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, we may not have to mention this "The ScheduledQueryConfiguration field constraints are final; the L2 tracks the published @aws-cdk/aws-service-spec for the AWS::CloudWatch::LogAlarm schema." unless needed. It will confuse the reviewer further.

@chintan-vaghani2008

Copy link
Copy Markdown

Changes now looks good to me.

Comment thread text/0960-logalarm-l2.md Outdated
Comment thread text/0960-logalarm-l2.md
Comment thread text/0960-logalarm-l2.md
Comment thread text/0960-logalarm-l2.md Outdated
Comment thread text/0960-logalarm-l2.md Outdated
- logGroups accepts ILogGroupRef[] instead of logGroupIdentifiers: string[];
  correct the circular-dependency rationale (ILogGroupRef lives in the shared
  generated interface layer and is already used cross-module)
- document IAM role behaviour: roles are created when omitted and never
  mutated when supplied; explain why addLogGroup() is not offered
- document scheduled query observability and why no metric*() helpers
- align the synth validation list with the implemented checks
- fix author handle and the actionLogLineRole auto-creation wording
Comment thread text/0960-logalarm-l2.md
Follows the Roles section of the CDK Design Guidelines and the Function /
StateMachine / Project / DeliveryStream precedent: the construct grants the
permissions the feature needs to whichever role is in use, created or supplied,
scoped to the log groups in logGroups. Trust is still not modified on a supplied
role. Callers who need an untouched role use Role.fromRoleArn with
mutable: false, and addToRolePolicy is exposed per the guidelines.

@matboros matboros left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mergify

mergify Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Thank you for contributing! Your pull request is now being automatically merged.

@mergify mergify Bot added the queued label Aug 31, 2026
@mergify

mergify Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-31 10:33 UTC · Rule: default · triggered by rule automatic merge
  • ✅ Checks passed · on draft merge queue: checking #962 on main (7d8a862) #991
  • ✅ Merged — 2026-08-31 10:34 UTC · at 7820d2b7a361d5e4fa5a6ca092326dca66793b2d · squash

This pull request spent 50 seconds in the queue, including 27 seconds running CI.

Required conditions to merge

@mergify mergify Bot mentioned this pull request Aug 31, 2026
18 tasks
@mergify
mergify Bot merged commit 9fb5468 into aws:main Aug 31, 2026
4 checks passed
@mergify mergify Bot removed the queued label Aug 31, 2026
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.

3 participants