BoundaryML/baml · error

AWS region expected, please set: env.{v}

Error message

AWS region expected, please set: env.{v}

What it means

When building the BedrockRuntimeClient, if the region property references an environment variable via the '$VAR' syntax, the client checks the value; if the region string still starts with '$' it means the env var was never substituted/set, so it errors with 'AWS region expected, please set: env.{v}'. This prevents sending a literal '$MY_REGION' as an AWS region.

Source

Thrown at engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs:656

                    None => None,
                },
                session_token: match &self.properties.session_token {
                    Some(session_token) => {
                        if session_token.starts_with("$") {
                            None
                        } else {
                            Some(session_token.clone())
                        }
                    }
                    None => None,
                },
            }),
        };

        // Set region if specified
        if let Some(aws_region) = self.properties.region.as_ref() {
            if let Some(v) = aws_region.strip_prefix("$") {
                return Err(anyhow::anyhow!("AWS region expected, please set: env.{v}",));
            }

            loader = loader.region(Region::new(aws_region.clone()));
        }

        let config = loader.load().await;
        let http_client = custom_http_client::client()?;

        let mut bedrock_config = aws_sdk_bedrockruntime::config::Builder::from(&config)
            // To support HTTPS_PROXY https://github.com/awslabs/aws-sdk-rust/issues/169
            .http_client(http_client)
            // Adding a custom http client (above) breaks the stalled stream protection for some reason. If a bedrock request takes longer than 5s (the default grace period, it makes it error out), so we disable it.
            .stalled_stream_protection(StalledStreamProtectionConfig::disabled())
            .interceptor(CollectorInterceptor::new(
                call_stack,
                http_request_id.clone(),
                &self.properties,
            ));

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Set the referenced environment variable (e.g. export AWS_REGION=us-east-1) before running.
  2. Verify the variable name after '$' matches exactly what is defined in your environment/.env.
  3. Alternatively hardcode the region string in client options to avoid env substitution entirely.

Example fix

// before
options { region $AWS_REGION }  // AWS_REGION unset
// after
export AWS_REGION=us-east-1  # then run, or:
options { region us-east-1 }
Defensive patterns

Strategy: validation

Validate before calling

import os
var = 'AWS_REGION'
if f'${var}' in str(client_options.get('region', '')):
    assert os.environ.get(var), f"env {var} must be set for aws-bedrock region"

Try / catch

try:
    resp = baml_client.MyFunction(...)
except Exception as e:
    if 'AWS region expected, please set' in str(e):
        # missing env var referenced as $VAR in region option
        raise RuntimeError('Set the AWS region env var or hardcode region in options') from e
    raise

Prevention

When it happens

Trigger: Client options contain region $AWS_REGION (or similar), and the referenced environment variable is undefined at runtime so the placeholder is passed through unresolved.

Common situations: Missing AWS_REGION in the shell/CI/container; .env file not loaded by the process; variable name typo between the client config and the actual env var.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/38f86d90784bb954. Report an issue: GitHub.