Skip to content

fix: resolve runtime/setup issues in six 01-features samples - #2000

Open
rhbelson wants to merge 1 commit into
awslabs:mainfrom
rhbelson:fix/features-runtime-fixes
Open

fix: resolve runtime/setup issues in six 01-features samples#2000
rhbelson wants to merge 1 commit into
awslabs:mainfrom
rhbelson:fix/features-runtime-fixes

Conversation

@rhbelson

Copy link
Copy Markdown
Contributor

Summary

Six 01-features/ samples had code-level issues that prevented them from running cleanly. Each fix is applied and the touched file is gate-clean (ruff check + ruff format --check under the repo-root config, py_compile clean). Complements #1998 (CI-clean doc/CLI fixes) and #1999 (docstring + arity fixes) — no file overlap.

Fixes

# File Problem Fix
1 02-host/.../03-strands-openai/agent.py Hardcoded <YOUR_API_KEY>/<YOUR_API_BASE>/<YOUR_API_VERSION> → opaque Azure auth failure Read from env (AZURE_API_KEY/AZURE_API_BASE/AZURE_API_VERSION); fail fast with a clear message if unset
2 04-manage-context/memory/00-getting-started/04-quickstart-boto3.py Hardcoded QuickstartMemoryValidationException on re-run Timestamp suffix QuickstartMemory_{int(time.time()) % 100000} (underscore per the [a-zA-Z][a-zA-Z0-9_]{0,47} regex)
3 06-observe/.../01-observe/data_protection.py data-identifier/PhoneNumber is not a valid managed identifier → policy fails Corrected to PhoneNumber-US in both the audit and de-identify statements
4 05-auth/.../04-outbound-auth-self-hosted/self_hosted_agent_oauth.py Required manual create_cognito.sh run + copy 6 env vars; script path not resolved relative to itself Auto-run create_cognito.sh (resolved relative to __file__), parse its exported values, inject into the environment when the OAuth vars are unset; --create-cognito still works
5 07-centralize/.../gatewaylabproject/scripts/waf/deploy.py associate_web_acl fails with WAFUnavailableEntityException (gateway eventual consistency) Retry loop (up to 6× with 10s backoff) around the associate call, catching that specific exception
6 04-manage-context/memory/00-getting-started/05-quickstart-agentcore-sdk.py Required MEMORY_EXECUTION_ROLE_ARN set manually; hardcoded name fails on re-run Auto-create the execution role if missing (mirrors the boto3 quickstart) + unique memory name per run

Lint cleanup (no behavior change)

Each touched file also carried pre-existing whole-file ruff debt that the python-lint gate lints on any change. Cleaned it: import sort (I001), explicit check=False on a pre-existing subprocess.run that already handles returncode (PLW1510), and # noqa on intentional demo-style broad-except handlers (BLE001/S110) — consistent with the repo's tutorial-code philosophy (root config already relaxes E722).

Testing

  • python3 -m py_compile clean on all six files.
  • uvx ruff@0.16.4 check --config pyproject.tomlAll checks passed; ruff@0.16.4 format --check6 files already formatted (repo-root config, as CI uses).
  • Note on verification fidelity: fixes are source-verified + gate-verified here (not each live-deployed in this session). Fixes 1 (env-var fail-fast) and 4 (auto-cognito) are the highest-confidence structurally; 5 (WAF retry) and 6 (auto-role) exercise runtime branches worth a live confirmation before merge if desired.

- 03-strands-openai/agent.py: read Azure OpenAI credentials from env
  (AZURE_API_KEY/AZURE_API_BASE/AZURE_API_VERSION) and fail fast with a clear
  message instead of hardcoding <YOUR_API_KEY> placeholders that silently error
- memory/00-getting-started/04-quickstart-boto3.py: append a timestamp suffix to
  the memory name so re-runs don't hit ValidationException on the unique-name rule
- memory/00-getting-started/05-quickstart-agentcore-sdk.py: auto-create the
  execution role if MEMORY_EXECUTION_ROLE_ARN is unset (mirrors the boto3
  quickstart) and give the memory a unique name per run
- 01-observe/data_protection.py: correct the invalid managed data identifier
  PhoneNumber -> PhoneNumber-US in both the audit and de-identify policies
- 04-outbound-auth-self-hosted/self_hosted_agent_oauth.py: auto-run create_cognito.sh
  (resolved relative to the script) and inject its exported values when the OAuth
  env vars are unset, so the sample runs end-to-end without manual copy-paste
- waf/deploy.py: retry associate_web_acl on WAFUnavailableEntityException (gateway
  eventual consistency) with backoff

Also cleaned pre-existing whole-file ruff findings in the touched files (import
sort, explicit subprocess check=False, noqa on intentional demo broad-except) so
the python-lint gate passes; no behavior change from the lint cleanup.
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.

1 participant