Skip to content

invoke command uses wrong region when AWS_REGION or profile region differs from deploy region #515

@jariy17

Description

@jariy17

Bug Description

The agentcore invoke command can invoke an agent in the wrong AWS region. The TUI displays one region (e.g. us-east-1) but the actual API call targets a different region (e.g. us-west-2), causing an error like:

ResourceNotFoundException: Agent runtime arn:aws:bedrock-agentcore:us-west-2:... not found

Root Cause

In src/lib/schemas/io/config-io.ts:122-153, the readAWSDeploymentTargets() method silently overrides the saved deployment region with:

  1. AWS_REGION or AWS_DEFAULT_REGION environment variables
  2. The region from the user's AWS profile config

This override happens at read time, so the region used for invocation can differ from the region where the agent was actually deployed. The agent's runtime ARN still contains the original deploy region, creating a mismatch.

Steps to Reproduce

  1. Deploy an agent to us-east-1: agentcore deploy
  2. Set AWS_REGION=us-west-2 in your environment (or have a profile that defaults to us-west-2)
  3. Run agentcore invoke
  4. The TUI shows Target: us-east-1 but the invoke call targets us-west-2, resulting in a ResourceNotFoundException

Expected Behavior

The invoke command should use the region where the agent was actually deployed (i.e. the region embedded in the runtime ARN or saved in aws-targets.json), not the environment/profile region override.

Suggested Fix

For the invoke command, the region should be derived from the deployed agent's ARN or the saved deployment targets, not overridden by environment variables. The environment/profile region override makes sense for deploy (choosing where to deploy) but not for invoke (targeting an already-deployed resource).

Affected Code

  • src/lib/schemas/io/config-io.ts lines 134-147 — region override logic
  • src/cli/commands/invoke/action.ts lines 88, 98, 130 — uses overridden region
  • src/cli/tui/screens/invoke/useInvokeFlow.ts lines 62, 149 — loads and uses overridden region

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions