-
Notifications
You must be signed in to change notification settings - Fork 576
Feat/aws profile auth support #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,14 @@ | ||
| STREAM_API_KEY=your_stream_api_key_here | ||
| STREAM_API_SECRET=your_stream_api_secret_here | ||
|
|
||
| AWS_BEARER_TOKEN_BEDROCK= | ||
| # AWS authentication (choose one approach): | ||
| # Option 1: AWS Profile (recommended for SSO/local dev) | ||
| AWS_PROFILE= | ||
|
|
||
| # Option 2: Explicit credentials | ||
| AWS_ACCESS_KEY_ID= | ||
| AWS_SECRET_ACCESS_KEY= | ||
|
|
||
| FAL_KEY= | ||
| CARTESIA_API_KEY= | ||
| DEEPGRAM_API_KEY= | ||
| DEEPGRAM_API_KEY= |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,12 @@ | |
| ) | ||
| from getstream.video.rtc import PcmData | ||
| from getstream.video.rtc.audio_track import AudioStreamTrack | ||
| from smithy_aws_core.identity.environment import EnvironmentCredentialsResolver | ||
| import boto3 | ||
| from smithy_aws_core.identity.components import ( | ||
| AWSCredentialsIdentity, | ||
| AWSIdentityProperties, | ||
| ) | ||
| from smithy_core.aio.interfaces.identity import IdentityResolver | ||
| from vision_agents.core.agents.agent_types import AgentOptions | ||
| from vision_agents.core.edge.types import Participant | ||
| from vision_agents.core.llm import realtime | ||
|
|
@@ -34,6 +39,44 @@ | |
| FORCE_RECONNECT_IN_MINUTES = 7.0 | ||
|
|
||
|
|
||
| class Boto3CredentialsResolver( | ||
| IdentityResolver[AWSCredentialsIdentity, AWSIdentityProperties] | ||
| ): | ||
| """IdentityResolver that delegates to boto3.Session for credential resolution. | ||
|
|
||
| Supports the full boto3 credential chain: env vars, shared credentials files, | ||
| AWS profiles, SSO, EC2 instance profiles, etc. | ||
| """ | ||
|
|
||
| def __init__(self, profile_name: Optional[str] = None) -> None: | ||
| self._session = boto3.Session(profile_name=profile_name) | ||
| self._cached: Optional[AWSCredentialsIdentity] = None | ||
|
|
||
| async def get_identity( | ||
| self, *, properties: AWSIdentityProperties, **kwargs: Any | ||
| ) -> AWSCredentialsIdentity: | ||
| if self._cached is not None: | ||
| return self._cached | ||
|
|
||
| credentials = self._session.get_credentials() | ||
| if not credentials: | ||
| raise ValueError("Unable to load AWS credentials via boto3") | ||
|
|
||
| creds = credentials.get_frozen_credentials() | ||
| if not creds.access_key or not creds.secret_key: | ||
| raise ValueError("AWS credentials are incomplete") | ||
|
|
||
| expiry = getattr(credentials, "_expiry_time", None) | ||
|
|
||
| self._cached = AWSCredentialsIdentity( | ||
| access_key_id=creds.access_key, | ||
| secret_access_key=creds.secret_key, | ||
| session_token=creds.token or None, | ||
| expiration=expiry, | ||
| ) | ||
| return self._cached | ||
|
Comment on lines
+51
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result:
Citations:
Remove credential caching to enable boto3's automatic refresh. Caching Remove the cache and call 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| class RealtimeConnection: | ||
| """Encapsulates a single AWS Bedrock bidirectional stream connection. | ||
|
|
||
|
|
@@ -154,6 +197,7 @@ def __init__( | |
| region_name: str = "us-east-1", | ||
| voice_id: str = "matthew", | ||
| reconnect_after_minutes=5.0, # Attempt to reconnect during silence after 5 minutes. Reconnect is forced after 7 minutes | ||
| aws_profile: Optional[str] = None, | ||
| **kwargs, | ||
| ) -> None: | ||
| """ """ | ||
|
|
@@ -173,7 +217,9 @@ def __init__( | |
| config = Config( | ||
| endpoint_uri=f"https://bedrock-runtime.{region_name}.amazonaws.com", | ||
| region=region_name, | ||
| aws_credentials_identity_resolver=EnvironmentCredentialsResolver(), | ||
| aws_credentials_identity_resolver=Boto3CredentialsResolver( | ||
| profile_name=aws_profile | ||
| ), | ||
| ) | ||
| self.client = BedrockRuntimeClient(config=config) | ||
| self.logger = logging.getLogger(__name__) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
Does the AWS boto3bedrock-runtimeclient support authenticating with an API key mapped toaws_session_token, or should profile / standard AWS credentials remain the only supported auth inputs here?💡 Result:
No—
aws_session_tokenin boto3/botocore is only the third value in the standard AWS credential triple (access key ID + secret access key + session token) used for SigV4-signed requests; it’s not a generic “API key” slot, and you can’t authenticate tobedrock-runtimeby stuffing a Bedrock API key intoaws_session_token. [1][2]If you want API-key-style auth for Amazon Bedrock Runtime, AWS provides Bedrock API keys that are sent as a Bearer token (for example via the environment variable
AWS_BEARER_TOKEN_BEDROCK, or anAuthorization: Bearer ...header). With recent SDKs, boto3 will work when that env var is set and you create a normalboto3.client("bedrock-runtime", ...). [1][3]So the supported auth inputs are:
aws_session_tokenas part of temporary creds. [2]AWS_BEARER_TOKEN_BEDROCK(not viaaws_session_token). [1][3]Sources
[1] Amazon Bedrock User Guide – “Use an Amazon Bedrock API key” (
AWS_BEARER_TOKEN_BEDROCK,Authorization: Bearer ..., boto3 example)[2] Boto3 credentials guide (defines
aws_access_key_id/aws_secret_access_key/aws_session_tokenas AWS credentials)[3] AWS ML Blog (Jul 8, 2025) – Bedrock API keys; SDKs detect
AWS_BEARER_TOKEN_BEDROCKand support API-key authenticationRemove
AWS_BEDROCK_API_KEYoverride toaws_session_token—it's not a valid Bedrock authentication method.The code at lines 80–81 maps
AWS_BEDROCK_API_KEYtoaws_session_token, butaws_session_tokenin boto3 is only the session-token component of standard AWS credentials (SigV4), not a slot for Bedrock API keys. According to AWS Bedrock documentation, Bedrock API keys should be passed via theAWS_BEARER_TOKEN_BEDROCKenvironment variable, which boto3 detects and uses automatically. The current code both misuses the boto3 API and clobbers any profile-derived credentials set by the newaws_profilepath.Either remove this block entirely if only standard AWS credentials should be supported, or replace it with proper Bedrock API key handling via
AWS_BEARER_TOKEN_BEDROCK.🤖 Prompt for AI Agents