Skip to content

[Python] Add CloudWatch Logs Basics scenario + Hello#7976

Open
scmacdon wants to merge 1 commit into
mainfrom
codeloom/cloudwatch-logs-basics-20260710
Open

[Python] Add CloudWatch Logs Basics scenario + Hello#7976
scmacdon wants to merge 1 commit into
mainfrom
codeloom/cloudwatch-logs-basics-20260710

Conversation

@scmacdon

Copy link
Copy Markdown
Contributor

Summary

This PR adds Python code examples for CloudWatch Logs generated by the CodeLoom
automated pipeline.

Files Added

  • python/example_code/cloudwatch-logs/hello/hello_cloudwatch-logs.py — Hello World example
  • python/example_code/cloudwatch-logs/scenarios/cloudwatch-logs_basics_scenario.py — Scenario
  • python/example_code/cloudwatch-logs/cloudwatch-logs_wrapper.py — Service wrapper class
  • python/example_code/cloudwatch-logs/test/test_cloudwatch-logs_integ.py — Integration tests
  • python/example_code/cloudwatch-logs/requirements.txt — Dependencies
  • .doc_gen/metadata/cloudwatch-logs_metadata.yaml — Metadata for doc generation

Operations Covered

(See specification for full list)

Generation Details

  • Spec Operation ID: amazon-cloudwatch-logs-spec-20260710-141825
  • Codegen Operation ID: amazon-cloudwatch-logs-codegen-20260710-142127
  • Generated: 2026-07-10 14:26 UTC
  • Pipeline Version: 1.0 (PoC)

Review Checklist

  • Code compiles/runs without errors
  • Snippet tags are correct and complete
  • Metadata YAML matches code structure
  • Scenario workflow makes logical sense for the service
  • Error handling covers realistic failure cases
  • Hello example demonstrates basic connectivity
  • Integration tests pass
  • No hardcoded credentials or account-specific values

@scmacdon scmacdon added auto-generated Python This issue relates to the AWS SDK for Python (boto3) needs-review labels Jul 10, 2026
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

@awsdocs awsdocs deleted a comment from github-actions Bot Jul 10, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 AI Code Example Review

FAIL. The PR is critically incomplete and broken: the main scenario file (scenario_cloudwatch_logs_basics.py) referenced by both the test file and the metadata is entirely absent from the PR, meaning neither the scenario nor the integration tests can execute. Additionally, several structural and quality issues prevent this from meeting AWS SDK example standards.

Detailed Review

  1. [BLOCKING] Missing scenario file: The test file cloudwatch-logs_basics_scenario.py imports from scenario_cloudwatch_logs_basics import CloudWatchLogsScenario, and the metadata references the snippet tag python.example_code.cloudwatch-logs.CloudWatchLogsScenario, but no such file exists anywhere in the PR. This is the core deliverable of the PR and it is simply not present. Nothing can run without it.

  2. [BLOCKING] Wrong file placed in scenarios directory: The file python/example_code/cloudwatch-logs/scenarios/cloudwatch-logs_basics_scenario.py contains integration test code (with import pytest, @pytest.mark.integ, etc.), not a scenario. It appears the test file was accidentally placed in the scenarios directory. It should live under test/ and the actual scenario implementation should be in scenarios/.

  3. [BLOCKING] Missing test directory and unit tests: Per AWS Python example standards, there should be a test/ directory with unit tests using stubbers (not just integration tests). The comparable examples in the knowledge base use stubber_factory.py and include a CloudWatchLogsStubber. Only integration tests are present, which cannot be run in CI without real AWS credentials and will incur charges.

  4. [BLOCKING] Missing README.md: All comparable premium examples include a README.md in the example directory. This file is completely absent from the PR.

  5. [STRUCTURAL] File naming inconsistency: The PR description mentions hello/hello_cloudwatch-logs.py but the actual file is at cloudwatch_logs_hello.py (flat, not in a hello/ subdirectory, and using underscores not hyphens). The metadata github path points to python/example_code/cloudwatch-logs for the Hello example but the standard pattern places Hello examples in a hello/ subdirectory.

  6. [STRUCTURAL] Metadata YAML destructively overwrites existing entries: The diff removes all pre-existing entries for other languages (.NET, Java, JavaScript, Kotlin, C++, SAP ABAP) from cloudwatch-logs_metadata.yaml. This is extremely destructive — it deletes working examples for AssociateKmsKey, CancelExportTask, CreateExportTask, DescribeLogStreams, DescribeExportTasks, DescribeSubscriptionFilters, DeleteSubscriptionFilter, PutSubscriptionFilter, GetLogEvents, and the BigQuery scenario. The PR should only add Python entries to existing action blocks, not replace them.

  7. [QUALITY] Unused import in wrapper: from datetime import datetime, timezone is imported in cloudwatch-logs_wrapper.py but never used. This will trigger pylint warnings and fails the linting standard.

  8. [QUALITY] get_query_results polling lacks a timeout/max-retries guard: The while True loop in get_query_results polls indefinitely with only a 1-second sleep. If the query stays in Running or Scheduled state for an extended period (e.g., due to service issues), this will hang forever. A maximum wait time or retry count should be enforced.

  9. [QUALITY] start_live_tail event_stream not closed on exception: If a ClientError or unexpected exception occurs after event_stream is opened inside the for-loop, the stream is not explicitly closed in a finally block. This can leak resources.

  10. [QUALITY] requirements.txt missing newline at EOF and pytest belongs in a dev/test dependency: pytest>=7.0.0 is a test-only dependency. Standard practice is to separate it (e.g., pytest in a requirements-test.txt or clearly comment it). Also, the file is missing a trailing newline which is a minor style issue but noted in the diff.


This review was generated automatically using Amazon Bedrock. It compares your changes against existing examples and coding guidelines. Please use your judgment — this is advisory, not authoritative.

@@ -0,0 +1,144 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 This file contains integration test code (pytest fixtures, @pytest.mark.integ decorators) but is placed in the scenarios/ directory. It should be moved to test/test_cloudwatch-logs_integ.py. The actual scenario implementation (CloudWatchLogsScenario class with run_scenario()) is missing entirely and needs to be created.

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

from cloudwatch_logs_wrapper import CloudWatchLogsWrapper
from scenario_cloudwatch_logs_basics import CloudWatchLogsScenario

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 from scenario_cloudwatch_logs_basics import CloudWatchLogsScenario — this import will fail at runtime because scenario_cloudwatch_logs_basics.py does not exist in the PR. The scenario file must be created.

"""

import logging
import time

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 from datetime import datetime, timezone is imported but never used anywhere in the file. Remove this import to avoid pylint W0611 (unused-import) errors.

query_string,
)
raise

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 The while True polling loop has no timeout or maximum retry limit. If the Insights query remains in Running/Scheduled state indefinitely (e.g., service issue), this will hang forever. Add a max_attempts parameter or a wall-clock timeout (e.g., 5 minutes) and raise an error if exceeded.

"Live Tail session started (ID: %s).",
session_start.get("sessionId", "unknown"),
)
elif "sessionUpdate" in event:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 The event_stream is not closed in a finally block. If an unhandled exception occurs during event iteration, the streaming connection will leak. Wrap the iteration in a try/finally that calls event_stream.close().

@@ -1,398 +1,205 @@
# zexi 0.2.0
cloudwatch-logs_AssociateKmsKey:
cloudwatch-logs_Hello:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 This diff completely removes existing entries for other languages (.NET, Java, JavaScript, Kotlin, C++, SAP ABAP) including actions like AssociateKmsKey, CancelExportTask, DescribeSubscriptionFilters, etc. Python entries should be ADDED to the existing action blocks, not used to replace all other languages. This will break documentation for all other SDK languages.

@@ -0,0 +1,2 @@
boto3>=1.26.0
pytest>=7.0.0 No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Missing newline at end of file. More importantly, pytest is a test-only dependency. Consider separating it into a requirements-test.txt or at minimum adding a comment like # Test dependencies. Also botocore should be listed explicitly since it is a direct dependency in error handling.



# snippet-start:[python.example_code.cloudwatch-logs.Hello]
def hello_cloudwatch_logs():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Per AWS example standards, the Hello example should accept the boto3 client as a parameter (e.g., def hello_cloudwatch_logs(logs_client)) rather than creating it internally. This makes the function testable with stubbers and follows the pattern seen in comparable examples like hello_medical_imaging(medical_imaging_client).

"""
try:
params = dict()
params["logGroupName"] = log_group_name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Style nit: params = dict() throughout the file should use params = {} (literal syntax), and list() should use []. The dict/list literal style is more idiomatic Python and is preferred per PEP 8 and the comparable premium examples.

# Mock user inputs for the scenario:
# Press Enter (multiple times for continue prompts), then "y" for cleanup
answers = [
"", # Press Enter to start

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 input_mocker is referenced as a pytest fixture but there is no conftest.py in the PR that defines it. Without this fixture definition, the test will fail with a fixture-not-found error. A conftest.py providing input_mocker (and likely stubber) must be added.

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

Labels

auto-generated needs-review Python This issue relates to the AWS SDK for Python (boto3)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant