Skip to content

fix(vectorize): support session tokens and default AWS credential chain in BedrockVectorizer - #865

Open
pcbeingused333 wants to merge 6 commits into
redis:mainfrom
pcbeingused333:fix/bedrock-session-token
Open

pcbeingused333 wants to merge 6 commits into
redis:mainfrom
pcbeingused333:fix/bedrock-session-token

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

BedrockVectorizer only read aws_access_key_id / aws_secret_access_key and raised ValueError when either was missing. It never forwarded aws_session_token, so temporary (STS) credentials were rejected by AWS, and SSO profiles, IAM roles and container/instance credentials could not be used at all because boto3's default credential chain was never reached.

Changes

Session token and default credential chain

_initialize_client now also reads aws_session_token (from api_config or AWS_SESSION_TOKEN) and forwards it together with the static keys. When neither static key is set, no credential arguments are passed to boto3.client, so boto3's default chain (SSO, IAM role, shared profile, container/instance credentials) applies. Supplying only one of the two keys raises a ValueError that names both. Extra **kwargs still reach boto3.client.

  • Docstrings updated for the new option and the narrower ValueError.
  • New tests/unit/test_bedrock_vectorizer.py with a mocked boto3 (no network).

Release Notes

BedrockVectorizer accepts aws_session_token (or AWS_SESSION_TOKEN) and, when no static keys are given, uses boto3's default credential chain instead of raising ValueError.

AI Assistance

  • No AI assistance was used for this PR.
  • This PR is AI-assisted. I have reviewed and understood everything in it, and I take responsibility for it.

Claude Code: implementation, tests and description.

Reviewer Brief

Start here: redisvl/utils/vectorize/bedrock.py, _initialize_client(). It decides which credential arguments reach boto3.client.

Where it could fail

  • redisvl/utils/vectorize/bedrock.py, retry rule: TypeError and the credential and SSO login errors skip retries; since 5a9ec15 this includes UnauthorizedSSOTokenError and TokenRetrievalError for expired SSO logins, also from the constructor's dimension check (two regression cases using botocore credential resolution).

Not verified: the live AWS Bedrock service, real SSO/IAM-role sessions; the full unit suite (this test file was run with --noconftest, since the repo conftest starts a Docker Redis it doesn't need).

Beyond CI: 12 of the 14 tests fail on 45a5df4 and all pass on this branch. With botocore 1.44.10, an SSO profile with no cached token raises SSOTokenLoadError from the constructor, and partial credentials (environment or shared files) raise PartialCredentialsError from boto3.client itself; a failed refresh of expiring environment credentials raises it from the embed call, unwrapped.

Since the last brief: explicit credentials are validated (token without keys, conflicting values), environment credentials are left to boto3, and missing or partial credentials and missing SSO login surface without retries.

Reviewed 471bd32 · Claude Code (claude-sonnet-5-5) · lenses: correctness, tests, docs


Note

Medium Risk
Touches AWS authentication and client initialization for all Bedrock embeddings; behavior changes when only env/SSO credentials are used and when auth fails mid-call, though coverage is strong in new unit tests.

Overview
BedrockVectorizer no longer requires static access keys up front. Explicit credentials now support aws_session_token (from api_config or constructor kwargs), with validation for partial key pairs, session token without keys, and conflicting api_config vs kwargs. When callers pass no explicit keys, credential env vars are not copied into boto3.client so botocore can use its default chain and refresh (SSO, IAM roles, etc.); only region_name and other kwargs are forwarded.

Embed paths switch Tenacity to _is_retryable, which skips retries on TypeError and several botocore credential/SSO errors (NoCredentialsError, PartialCredentialsError, SSOTokenLoadError, TokenRetrievalError, UnauthorizedSSOTokenError). Those exceptions are re-raised from _set_model_dims, _embed, and _embed_many instead of being wrapped as generic ValueErrors or retried up to six times.

Adds tests/unit/test_bedrock_vectorizer.py covering token forwarding, default chain, validation, credential error surfacing from construction and embed calls, and expired SSO profiles (no live AWS).

Reviewed by Cursor Bugbot for commit 5a9ec15. Bugbot is set up for automated code reviews on this repo. Configure here.

…in in BedrockVectorizer

BedrockVectorizer required static aws_access_key_id/aws_secret_access_key and never forwarded a session token, so temporary (STS/SSO) and IAM-role credentials failed. Forward aws_session_token (api_config or AWS_SESSION_TOKEN) and fall back to boto3's default credential chain when no static keys are given.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread redisvl/utils/vectorize/bedrock.py Resolved
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Pushed a follow-up commit (62ab031): AWS_SESSION_TOKEN from the environment is now only used when the access key and secret also come from the environment. If explicit keys are passed in api_config, a leftover environment token is no longer attached to them (that mix would fail authentication). Added a unit test for this case.

This comment was drafted with Claude Code.

Comment thread redisvl/utils/vectorize/bedrock.py Resolved
Comment thread redisvl/utils/vectorize/bedrock.py Resolved
Comment thread redisvl/utils/vectorize/bedrock.py Resolved
Comment thread redisvl/utils/vectorize/bedrock.py Resolved
…-credentials errors

- Do not copy AWS_* environment credentials into client kwargs; boto3
  resolves them itself and keeps refresh support.
- Reject an explicit aws_session_token without access key and secret.
- Reject conflicting credential values between api_config and kwargs;
  keep forwarding unrelated boto3 options.
- Propagate NoCredentialsError without retries or ValueError wrapping.
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. Pushed a follow-up commit addressing all four points:

  • Environment credentials (including AWS_SESSION_TOKEN) are no longer copied into the client kwargs; when no explicit credentials are supplied, boto3 resolves them itself, so refreshable credentials keep working. The env-token test now asserts nothing is copied.
  • An explicit aws_session_token without access key and secret now raises ValueError before the client is created.
  • Conflicting credential values between api_config and constructor kwargs raise ValueError; unrelated boto3 kwargs are still forwarded.
  • NoCredentialsError is excluded from the tenacity retries and propagates unwrapped from _embed, _embed_many and the dimension check, so a caller with no credentials gets it on the first attempt.

Unit tests cover each case.

This comment was drafted with Claude Code.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread redisvl/utils/vectorize/bedrock.py Resolved
Comment thread redisvl/utils/vectorize/bedrock.py Resolved
Comment thread tests/unit/test_bedrock_vectorizer.py Resolved
pcbeingused333 and others added 2 commits November 25, 2026 00:41
Treat SSOTokenLoadError like NoCredentialsError in the constructor, embed
and embed_many paths, and skip the botocore-dependent tests when the SDK
is not installed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Thanks, both points are addressed in follow-up commits:

  • SSOTokenLoadError is now excluded from the retries and propagates unwrapped from the constructor, embed and embed_many; regression tests assert it surfaces on the first attempt. With an SSO profile and an empty token cache, the constructor now raises SSOTokenLoadError directly.
  • PartialCredentialsError raised while refreshing credentials is handled the same way.
  • The botocore-dependent tests use pytest.importorskip, so without the SDK the rest of the file passes and those are skipped.

Expired-token errors (UnauthorizedSSOTokenError, TokenRetrievalError) are outside the scope of this change and behave as before.

This comment was drafted with Claude Code.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 471bd32. Configure here.

Comment thread redisvl/utils/vectorize/bedrock.py Resolved

@vishal-bala vishal-bala left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the missing-login case and the optional SDK tests. I’m keeping changes requested for the expired SSO login case in the linked thread. Once the constructor surfaces the SDK’s login error on the first attempt for both SSO profile formats, I’m comfortable approving. Bugbot thread

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants