Skip to content

fix: make region optional in CodeInterpreter and code_session#523

Open
citizen204 wants to merge 2 commits into
aws:mainfrom
citizen204:fix-511-optional-region-code-interpreter
Open

fix: make region optional in CodeInterpreter and code_session#523
citizen204 wants to merge 2 commits into
aws:mainfrom
citizen204:fix-511-optional-region-code-interpreter

Conversation

@citizen204

Copy link
Copy Markdown
Contributor

Summary

CodeInterpreter.__init__ and code_session() required an explicit region string, making callers responsible for extracting the region even when they already have a configured boto3 session or standard AWS environment variables in place.

This PR makes region optional (defaults to None). When omitted, the region is resolved from the boto3 session via its standard chain (environment variables, config file, instance metadata, etc.). The session is created first (if not supplied), then the region is read from session.region_name.

Existing callers passing an explicit region string are unaffected.

Fixes #511

Changes

  • src/bedrock_agentcore/tools/code_interpreter_client.py:
    • CodeInterpreter.__init__: change region: strregion: Optional[str] = None; resolve region from session when not provided
    • code_session(): change region: strregion: Optional[str] = None
    • Update docstrings to reflect the new default behaviour

When no region is provided, resolve it from the boto3 session using
standard credential/config chain resolution (env vars, config file,
EC2 instance metadata, etc.) instead of requiring an explicit string.
This lets callers omit region when their environment already configures it.

Fixes aws#511
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@1eabc67). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...bedrock_agentcore/tools/code_interpreter_client.py 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #523   +/-   ##
=======================================
  Coverage        ?   89.38%           
=======================================
  Files           ?       98           
  Lines           ?     8582           
  Branches        ?     1273           
=======================================
  Hits            ?     7671           
  Misses          ?      586           
  Partials        ?      325           
Flag Coverage Δ
unittests 89.38% <33.33%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

CodeInterpreter should not require a region argument

3 participants