fix(payments): align boto3 region with AWS_REGION from .env#1673
Closed
fahadfa-aws wants to merge 1 commit into
Closed
fix(payments): align boto3 region with AWS_REGION from .env#1673fahadfa-aws wants to merge 1 commit into
fahadfa-aws wants to merge 1 commit into
Conversation
The tutorial .env files set AWS_REGION, but boto3 reads AWS_DEFAULT_REGION instead — AWS_REGION is the env var the AWS SDK for JavaScript honors, not the Python SDK. So a .env that sets AWS_REGION=us-west-2 is silently ignored by boto3, which then falls back to whatever ~/.aws/config has (commonly us-east-1). Resources get created in the wrong region without the script ever printing a warning. Add a small `resolve_region` helper in utils.py that promotes AWS_REGION to AWS_DEFAULT_REGION when the operator hasn't set AWS_DEFAULT_REGION explicitly, then returns the resolved value. The three tutorial scripts that hit the bug (deploy_payment_agent.py, bazaar_gateway_agent.py, utils.setup_cognito_user_pool) now call it before any boto3.Session() so all clients pick up the same region. The setup scripts (setup_agentcore_payments.py, multi_provider_setup.py) already pass region_name= explicitly to boto3.Session, so they aren't affected.
Author
|
@mvangara10 — flagging this for your review when you have a moment. Tagged across the full set of payments-tutorial fixes I've been pushing today; happy to walk through any of them. Audit logs and test evidence are referenced in the PR description. |
|
Latest scan for commit: Security Scan ResultsScan Metadata
SummaryScanner ResultsThe table below shows findings by scanner, with status based on severity thresholds and dependencies: Column Explanations: Severity Levels (S/C/H/M/L/I):
Other Columns:
Scanner Results:
Severity Thresholds (Thresh Column):
Threshold Source: Values in parentheses indicate where the threshold is configured:
Statistics calculation:
|
Author
|
Superseded by #1738 (consolidated PR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
The tutorial
.envfiles setAWS_REGION, but boto3 readsAWS_DEFAULT_REGIONfrom the environment and ignoresAWS_REGIONentirely (AWS_REGIONis the env var the AWS SDK for JavaScript honors; the Python SDK does not). So a.envthat setsAWS_REGION=us-west-2is silently ignored, andboto3.Session()falls back to whatever~/.aws/configsays — commonlyus-east-1. Resources get created in the wrong region without any warning.Live-reproduced today: with
AWS_REGION=us-west-2set and noAWS_DEFAULT_REGION,boto3.Session().region_namereturnsus-east-1(from~/.aws/config).The boto3 docs confirm
AWS_REGIONis not in the recognized env-var list: https://docs.aws.amazon.com/boto3/latest/guide/configuration.html#using-environment-variablesChanges
utils.py: add aresolve_region(default=\"us-west-2\")helper that promotesAWS_REGIONtoAWS_DEFAULT_REGIONwhen the operator hasn't setAWS_DEFAULT_REGIONexplicitly, then returns the resolved region. If both env vars are set, the operator's explicitAWS_DEFAULT_REGIONis preserved.Three call sites use the helper:
deploy_payment_agent.py:48-52— Tutorial 02 deploy scriptbazaar_gateway_agent.py:53-58— Tutorial 04 gateway scriptutils.setup_cognito_user_pool(line 467) — Cognito setup helperSetup scripts (
setup_agentcore_payments.py,multi_provider_setup.py) already passregion_name=explicitly toboto3.Session, so they aren't affected.Verification
Static — tested
resolve_region()against 4 env states with~/.aws/configset tous-east-1:AWS_REGION=us-west-2, noAWS_DEFAULT_REGIONus-east-1from~/.aws/config(silent skew)us-west-2AWS_DEFAULT_REGION=eu-west-1(operator explicit)eu-west-1eu-west-1(no overwrite)AWS_DEFAULT_REGIONonlyLive AWS — ran
agentcore deployagainstus-west-2withAWS_REGION=us-west-2andAWS_DEFAULT_REGIONunset:us-east-1AgentCore-PaymentAgent-defaultreachesCREATE_COMPLETEin us-west-2, confirmed not present in us-east-1. Stack torn down after.Notes
No hardcoded account, region, or ARN in the diff. The default fallback (
us-west-2) matches what the existing code uses (os.environ.get(\"AWS_REGION\", \"us-west-2\")); it's a last-resort fallback only when nothing else is set.