-
Notifications
You must be signed in to change notification settings - Fork 15
Deploy command incorrectly overrides aws-targets.json region with AWS_REGION env var #772
Description
Bug
resolveAWSDeploymentTargets() in config-io.ts:144 overrides the explicit region set in aws-targets.json with the AWS_REGION environment variable:
const envRegion = process.env.AWS_REGION ?? process.env.AWS_DEFAULT_REGION;
if (envRegion && AgentCoreRegionSchema.safeParse(envRegion).success) {
return targets.map(t => ({ ...t, region: envRegion }));
}If a user has AWS_REGION=us-east-1 set in their environment but configured us-west-2 in aws-targets.json, the deploy command silently deploys to us-east-1, completely ignoring the explicit configuration.
Root Cause
resolveAWSDeploymentTargets() was designed for post-deploy/read-only commands (like status) where the user might be in a different environment and needs to resolve the region dynamically. However, the deploy command also calls this function, which means the env var override applies during deployment — where the user's explicit aws-targets.json configuration should take precedence.
Expected Behavior
The deploy command should respect the region specified in aws-targets.json and not override it with the AWS_REGION environment variable.
Workaround
unset AWS_REGION && agentcore deployProposed Fix
The deploy command should use readAWSDeploymentTargets() (which preserves the saved region) instead of resolveAWSDeploymentTargets(). This is consistent with what the CDK app already does at cdk/bin/cdk.ts:29. The environment override logic should only apply to read-only commands, not deploy.