plandex-ai/plandex · error

failed to load AWS config: %v

Error message

failed to load AWS config: %v

What it means

loadAWSVars uses the AWS SDK's config.LoadDefaultConfig to build AWS credentials for Bedrock-style auth. This error means the SDK could not construct a config/credential chain at all (bad region string, malformed profile, or unrecoverable config error). Note callers deliberately swallow this error when PLANDEX_AWS_PROFILE is unset or fails, so it usually only surfaces via the fallback logging path.

Source

Thrown at app/cli/lib/model_credentials.go:330

			return s, nil
		}
	}

	content, err := os.ReadFile(pathOrJson)
	if err != nil {
		return "", err
	}

	return string(content), nil
}

func loadAWSVars(vars map[string]string) error {
	// disable IMDS to prevent slow request
	os.Setenv("AWS_EC2_METADATA_DISABLED", "true")

	cfg, err := config.LoadDefaultConfig(context.Background())
	if err != nil {
		return fmt.Errorf("failed to load AWS config: %v", err)
	}

	creds, err := cfg.Credentials.Retrieve(context.Background())
	if err != nil {
		return fmt.Errorf("failed to retrieve AWS credentials: %v", err)
	}

	vars["AWS_ACCESS_KEY_ID"] = creds.AccessKeyID
	vars["AWS_SECRET_ACCESS_KEY"] = creds.SecretAccessKey
	vars["AWS_REGION"] = cfg.Region
	if creds.SessionToken != "" {
		vars["AWS_SESSION_TOKEN"] = creds.SessionToken
	}

	return nil
}

func mergeAuthVars(dest, src map[string]string) {

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the profile named by PLANDEX_AWS_PROFILE/AWS_PROFILE exists in ~/.aws/credentials and ~/.aws/config.
  2. Validate ~/.aws/config and ~/.aws/credentials INI syntax (no duplicated or malformed keys).
  3. Set a valid AWS_REGION (e.g. us-east-1) in the environment or the profile.
  4. Test independently with `aws sts get-caller-identity --profile <profile>` to reproduce outside the CLI.

Example fix

// before
export PLANDEX_AWS_PROFILE="prod"
// after
export PLANDEX_AWS_PROFILE="prod"
export AWS_REGION="us-east-1"
grep -q "^\[prod\]" ~/.aws/credentials || echo "profile 'prod' missing from ~/.aws/credentials"
Defensive patterns

Strategy: validation

Validate before calling

func awsProfileReady() error {
    profile := os.Getenv("PLANDEX_AWS_PROFILE")
    if profile == "" { return nil }
    data, err := os.ReadFile(filepath.Join(os.Getenv("HOME"), ".aws", "credentials"))
    if err != nil { return err }
    if !strings.Contains(string(data), "["+profile+"]") {
        return fmt.Errorf("profile %q not found in ~/.aws/credentials", profile)
    }
    return nil
}

Try / catch

if err := loadAWSVars(vars); err != nil {
    log.Printf("AWS vars unavailable, continuing with env-var auth: %v", err)
    // the library already falls through to default env-var checks
}

Prevention

When it happens

Trigger: loadAWSVars runs (only when PLANDEX_AWS_PROFILE is set) and config.LoadDefaultConfig returns an error: invalid AWS_PROFILE name, malformed ~/.aws/config or ~/.aws/credentials, or an invalid AWS_REGION value that the SDK cannot parse.

Common situations: PLANDEX_AWS_PROFILE names a profile absent from ~/.aws/credentials, a hand-edited AWS config with broken INI syntax, an invalid region string, or a shared-credentials file with wrong permissions/format.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/f62bcd22af0e0ab0. Report an issue: GitHub.