Skip to content

[Python] Add greengrassv2 Basics scenario + Hello - #8147

Closed
RuiqiGao-aws wants to merge 1 commit into
awsdocs:mainfrom
RuiqiGao-aws:codeloom/pragent-pat-test
Closed

RuiqiGao-aws wants to merge 1 commit into
awsdocs:mainfrom
RuiqiGao-aws:codeloom/pragent-pat-test

Conversation

@RuiqiGao-aws

Copy link
Copy Markdown
Collaborator

Auto-generated Python code examples for greengrassv2 (Hello + Basics scenario + wrapper + tests)

@github-actions github-actions Bot added the Python This issue relates to the AWS SDK for Python (boto3) label Sep 23, 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

This PR is mostly well-structured and functional, but has several issues that need to be addressed before it can be approved: the tests are integration-only with no unit/mock tests (unlike comparable examples), an unused import base64 in the wrapper, a missing README.md, missing conftest.py, and the scenario does not use demo_tools.question for user interaction as is standard for Python basics scenarios in this repo.

Detailed Review

  1. No unit tests (blocking): The test file test_greengrassv2_basics.py contains only @pytest.mark.integ integration tests that hit live AWS. Comparable examples (e.g., controltower, medical-imaging) always include unit tests using pytest stubs/mocks in addition to integration tests. A conftest.py and stub-based unit tests should be added so CI can run without AWS credentials.

  2. Missing README.md (blocking): Every comparable Python basics example (controltower, medical-imaging, etc.) includes a README.md with prerequisites, instructions for setting up a virtual environment, and how to run the scenario. This is absent here.

  3. Unused import base64 in greengrassv2_wrapper.py: import base64 is imported at the top but never used anywhere in the file. This will trigger a linter warning and should be removed.

  4. No demo_tools.question for interactivity: Comparable Python basics scenarios (e.g., scenario_controltower.py, imaging_set_and_frames.py) use demo_tools.question to prompt users before each step, making scenarios genuinely interactive. This scenario runs non-interactively without any user prompts or the q.ask() pattern. The demo_tools path setup (sys.path.append('../..')) is also missing.

  5. Missing conftest.py: The test/ directory lacks a conftest.py. Every comparable example has one to set up sys.path and shared fixtures cleanly, rather than using sys.path.insert inline in the test file.

  6. ARN parsing is fragile: In _step2_create_component_v1 and in the test, the component ARN (without version) is derived by splitting on :versions:. This is brittle. The ARN format for Greengrass components is arn:aws:greengrass:<region>:<account>:components:<name>:versions:<version> — splitting on :versions: is reasonable but the approach should be documented, or better yet, the list_component_versions method should accept the full versioned ARN and strip the version internally, or the API should be called with the known name instead.

  7. time.sleep(3) in integration test: Using a hard-coded sleep to wait for a component to become DEPLOYABLE is fragile and may still fail in slow environments. A polling loop with a timeout and exponential backoff would be more robust and is consistent with the guideline about using waiters/polling where needed.

  8. cancel_deployment may fail silently in cleanup scenario: In _step10_cancel_deployment, if the deployment is already COMPLETED or INACTIVE (which is plausible since there are no real devices), the cancel_deployment call will raise a ConflictException. The scenario does not handle this case gracefully with a user-friendly message — it will propagate and likely prevent the completion message from printing (the finally block will still run, which is good, but the scenario will not print "complete!").

  9. pytest in requirements.txt is not a runtime dependency: pytest>=7.0.0 is a test/dev dependency and should not be in the main requirements.txt. It should either be in a separate requirements-test.txt or the test directory should have its own requirements.txt.

  10. Good aspects: The wrapper class is well-structured with good docstrings, proper pagination for all list operations, specific ClientError code handling per method, snippet tags are correctly placed, metadata YAML is complete and well-formed, _cleanup() is in a finally block, and unique suffixes are used to avoid resource name collisions. The Hello example is clean and follows the expected pattern.


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.

"""

import base64
import json

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.

🤖 Unused import: base64 is never used anywhere in this file. Remove it to avoid linter warnings.

"""

import sys
import os

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.

🤖 Prefer a conftest.py to handle sys.path manipulation rather than doing it inline here. See comparable examples like controltower/test/conftest.py.

"timeoutInSeconds": 60,
},
}
deploy_response = wrapper.create_deployment(

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.

🤖 time.sleep(3) is fragile. Consider polling with a timeout (e.g., retry up to 10 times with 2-second intervals checking component status) to wait for the component to become DEPLOYABLE, rather than a fixed sleep.

@@ -0,0 +1,3 @@
boto3>=1.26.0
botocore>=1.29.0
pytest>=7.0.0

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.

🤖 pytest is a test/development dependency, not a runtime dependency. Consider moving it to a requirements-test.txt or a test/requirements.txt file to follow the convention used in comparable examples.

"""

import json
import logging

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.

🤖 Comparable Python basics scenarios import and use demo_tools.question (e.g., import demo_tools.question as q) to prompt users before each step. Without q.ask() calls, this scenario is not interactive. Add sys.path.append('../..') and use q.ask() to pause between steps as the pattern requires.

)
print(f" ARN: {version.get('arn')}")

print("\nNote: Versions are listed with the greatest (newest) version first.")

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 cancel_deployment call may raise ConflictException if the deployment has already reached a terminal state (COMPLETED, CANCELED, FAILED). Since there are no real devices in this scenario, the deployment will likely complete or go INACTIVE almost immediately. Add handling here or in _step10_cancel_deployment to catch this gracefully and inform the user.

message="Hello from Greengrass Basics v2.0.0 - Enhanced Edition",
log_level="INFO",
)
response = self.wrapper.create_component_version(recipe)

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 ARN splitting logic self.v1_arn.rsplit(':versions:', 1) is fragile and undocumented. Consider adding a comment explaining the ARN format arn:aws:greengrass:<region>:<account>:components:<name>:versions:<version> to clarify why this split is safe.

@RuiqiGao-aws

Copy link
Copy Markdown
Collaborator Author

Closing: end-to-end diagnostic run of the CodeLoom PRAgent with a classic PAT instead of device flow, to confirm the auth path. Not for review.

@RuiqiGao-aws
RuiqiGao-aws deleted the codeloom/pragent-pat-test branch September 23, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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