Skip to content

fix(parser): accept CloudWatch Logs CONTROL_MESSAGE and keep extractedFields (#8869) - #8870

Open
dhairyakhandelwal880-dotcom wants to merge 1 commit into
aws-powertools:developfrom
dhairyakhandelwal880-dotcom:fix/cloudwatch-parser-control-message
Open

dhairyakhandelwal880-dotcom wants to merge 1 commit into
aws-powertools:developfrom
dhairyakhandelwal880-dotcom:fix/cloudwatch-parser-control-message

Conversation

@dhairyakhandelwal880-dotcom

Copy link
Copy Markdown
Contributor

Issue number: closes #8869

Summary

Changes

  • In aws_lambda_powertools/utilities/parser/models/cloudwatch.py:
    • In CloudWatchLogsDecode, made owner, logGroup, and logStream optional (str | None = None) and defaulted subscriptionFilters and logEvents to default_factory=list. When CloudWatch Logs emits a CONTROL_MESSAGE (e.g. to verify destination reachability), it sends only {"messageType": "CONTROL_MESSAGE"}.
    • In CloudWatchLogsLogEvent, added extracted_fields: dict[str, str] = Field(default_factory=dict, alias="extractedFields") and model_config = ConfigDict(populate_by_name=True) so fields extracted by CloudWatch subscription filter patterns are preserved.
  • In aws_lambda_powertools/utilities/parser/envelopes/cloudwatch.py:
    • In CloudWatchLogsEnvelope.parse(), return an empty list [] when parsed_envelope.awslogs.decoded_data.messageType == "CONTROL_MESSAGE".
    • Fixed copy-paste debug log message from "SNS model" to "CloudWatchLogs model".
  • Added unit tests in tests/unit/parser/_pydantic/test_cloudwatch.py covering:
    • CloudWatchLogsModel parsing of a CONTROL_MESSAGE event.
    • CloudWatchLogsEnvelope returning [] on CONTROL_MESSAGE.
    • CloudWatchLogsLogEvent keeping extractedFields.

User experience

  • Lambda functions triggered by CloudWatch Logs subscription filters will no longer fail validation when CloudWatch sends a CONTROL_MESSAGE heartbeat.
  • When CloudWatchLogsEnvelope is used with a schema model, CONTROL_MESSAGE events gracefully return [] without error.
  • Parsed log events retain extracted_fields when subscription filter pattern extraction is used.

Verification

Ran pytest tests/unit/parser/_pydantic/test_cloudwatch.py (all 12 tests passed) and full parser test suite (all 203 tests passed). Verified formatting and linting with ruff check and ruff format --check.


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

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@dhairyakhandelwal880-dotcom
dhairyakhandelwal880-dotcom requested a review from a team as a code owner November 18, 2026 15:44
@boring-cyborg boring-cyborg Bot added the tests label Nov 18, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 18, 2026
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: CloudWatchLogsModel and envelope reject CONTROL_MESSAGE events and drop extractedFields

1 participant