mem0ai/mem0 · critical · ValueError

AWS credentials not found. Please set AWS_ACCESS_KEY_ID, AWS

Error message

AWS credentials not found. Please set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION environment variables, or provide them in the config.

What it means

Raised by AWSBedrockLLM._initialize_aws_client when boto3 raises NoCredentialsError while creating the bedrock-runtime client — no credentials were discoverable via config, env vars, or the default credential chain, and the test connection fails. It is a config/environment error surfaced as ValueError at LLM construction time.

Source

Thrown at mem0/llms/aws_bedrock.py:95

        self.model_config = self.config.get_model_config()
        self.provider = extract_provider(self.config.model, self.config.provider_override)

        # Initialize provider-specific settings
        self._initialize_provider_settings()

    def _initialize_aws_client(self):
        """Initialize AWS Bedrock client with proper credentials."""
        try:
            aws_config = self.config.get_aws_config()

            # Create Bedrock runtime client
            self.client = boto3.client("bedrock-runtime", **aws_config)

            # Test connection
            self._test_connection()

        except NoCredentialsError:
            raise ValueError(
                "AWS credentials not found. Please set AWS_ACCESS_KEY_ID, "
                "AWS_SECRET_ACCESS_KEY, and AWS_REGION environment variables, "
                "or provide them in the config."
            )
        except ClientError as e:
            if e.response["Error"]["Code"] == "UnauthorizedOperation":
                raise ValueError(
                    f"Unauthorized access to Bedrock. Please ensure your AWS credentials "
                    f"have permission to access Bedrock in region {self.config.aws_region}."
                )
            else:
                raise ValueError(f"AWS Bedrock error: {e}")

    def _test_connection(self):
        """Test connection to AWS Bedrock service."""
        try:
            # List available models to test connection
            bedrock_client = boto3.client("bedrock", **self.config.get_aws_config())

View on GitHub (pinned to 001c235229)

Solutions

  1. Run aws configure (or set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION env vars)
  2. Or pass aws_access_key_id/aws_secret_access_key/aws_region in the mem0 LLM config
  3. On AWS compute, attach an IAM execution/task role with bedrock:InvokeModel and remove stale env credential overrides
  4. For SSO, re-authenticate: aws sso login --profile <profile> and export AWS_PROFILE

Example fix

// before
Memory.from_config({"llm": {"provider": "aws_bedrock"}})  # ValueError: credentials not found

# after
Memory.from_config({"llm": {"provider": "aws_bedrock", "config": {
    "aws_access_key_id": "...", "aws_secret_access_key": "...", "aws_region": "us-east-1"
}}})
Defensive patterns

Strategy: validation

Validate before calling

import os

def aws_creds_available(cfg) -> bool:
    if cfg.get("aws_access_key_id") and cfg.get("aws_secret_access_key"):
        return True
    return bool(os.getenv("AWS_ACCESS_KEY_ID") and os.getenv("AWS_SECRET_ACCESS_KEY")) or \
           os.path.isfile(os.path.expanduser("~/.aws/credentials"))

Try / catch

try:
    llm = AWSBedrockLLM(config)
except ValueError as e:
    if "AWS credentials not found" in str(e):
        raise SystemExit("Configure AWS creds: aws configure or env vars") from e
    raise

Prevention

When it happens

Trigger: No AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY env vars, no aws config keys in the mem0 LLM config, and no IAM role or ~/.aws/credentials on the host; running locally without aws configure having been run; container missing the mounted credentials

Common situations: Local development without AWS CLI setup; ECS/EKS task role misconfigured or missing; expired SSO session (aws sso login needed); CI runner with no AWS auth step.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/94d5a4d9bc75e5db. Report an issue: GitHub.