|
26 | 26 | cloudwatch_logs = boto3.client('logs', config=config) |
27 | 27 | lambda_client = boto3.client('lambda', config=config) |
28 | 28 |
|
| 29 | +SUPPORTED_LOG_GROUP_CLASS = "STANDARD" |
| 30 | + |
29 | 31 | def lambda_handler(event: Dict[str, Any], context) -> None: |
30 | 32 | """ |
31 | 33 | Main Lambda function handler that manages CloudWatch log group subscriptions. |
@@ -94,6 +96,9 @@ def lambda_handler(event: Dict[str, Any], context) -> None: |
94 | 96 | return |
95 | 97 |
|
96 | 98 | log_group_to_subscribe = event_detail['requestParameters']['logGroupName'] |
| 99 | + |
| 100 | + if not should_process_log_group_class(event_detail): |
| 101 | + return |
97 | 102 | found_log_group_in_regex_pattern = False |
98 | 103 |
|
99 | 104 | for regex_pattern in regex_pattern_list: |
@@ -250,6 +255,21 @@ def should_create_subscription(cloudwatch_logs, log_group_name: str, destination |
250 | 255 |
|
251 | 256 | return True |
252 | 257 |
|
| 258 | +def should_process_log_group_class(event_detail: Dict[str, Any]) -> bool: |
| 259 | + """ |
| 260 | + Allow standard log groups, including events where CloudTrail omits logGroupClass. |
| 261 | +
|
| 262 | + CloudFormation-created log groups default to STANDARD even when the property is |
| 263 | + not present in requestParameters. Explicit non-standard classes should still be |
| 264 | + ignored to preserve the existing behavior. |
| 265 | + """ |
| 266 | + log_group_class = event_detail.get('requestParameters', {}).get('logGroupClass', SUPPORTED_LOG_GROUP_CLASS) |
| 267 | + if log_group_class == SUPPORTED_LOG_GROUP_CLASS: |
| 268 | + return True |
| 269 | + |
| 270 | + logger.info(f"Skipping log group because logGroupClass {log_group_class} is not supported") |
| 271 | + return False |
| 272 | + |
253 | 273 | def add_subscription( |
254 | 274 | filter_name: str, |
255 | 275 | logs_filter: str, |
|
0 commit comments