-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Refactor AWS plugin with pool connection and async session #1849
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
Conversation
|
Hi @jayeshp19 I got two PR because internals of Livekit changed from
This PR #1849 is addressing The implemented You can move the region check into utils to make the code DRY
|
the purpose of are you getting any errors, if so can you share them? |
The
A better approach for credential validation would be to use def validate_aws_credentials(api_key=None, api_secret=None, session_token=None, region=None):
"""Validate AWS credentials by attempting to call STS get_caller_identity."""
try:
session = boto3.Session(
aws_access_key_id=api_key,
aws_secret_access_key=api_secret,
aws_session_token=session_token,
region_name=region or DEFAULT_REGION
)
sts = session.client('sts')
identity = sts.get_caller_identity()
return True, identity
except Exception as e:
return False, str(e) This approach:
|
Here is full test code. You can run it EC2 or CloudShell import boto3
import time
import botocore
# This simulates their current implementation
def get_aws_credentials():
# Gets and "freezes" credentials at a point in time
session = boto3.Session()
creds = session.get_credentials()
print(f"Got initial credentials: {creds.access_key[:4]}...{creds.secret_key[:4]}... (token present: {'Yes' if creds.token else 'No'})")
return creds
# Extract credentials at the beginning (like in their __init__)
frozen_creds = get_aws_credentials()
# Function that uses the frozen credentials
def test_with_frozen_creds():
try:
# Create a new session with only the access key and secret key (dropping token)
print(f"Using frozen credentials from earlier")
session = boto3.Session(
aws_access_key_id=frozen_creds.access_key,
aws_secret_access_key=frozen_creds.secret_key
# Notice: no token is passed here
)
sts = session.client('sts')
identity = sts.get_caller_identity()
print(f"Success! Identity: {identity['Arn']}")
return True
except Exception as e:
print(f"Failed with error: {str(e)}")
return False
# Function using credential provider chain properly
def test_with_provider_chain():
try:
print(f"Using credential provider chain")
session = boto3.Session()
sts = session.client('sts')
identity = sts.get_caller_identity()
print(f"Success! Identity: {identity['Arn']}")
return True
except Exception as e:
print(f"Failed with error: {str(e)}")
return False
print("Testing immediately after extraction:")
test_with_frozen_creds()
test_with_provider_chain() Here are my results ~ $ python test.py
Got initial credentials: ASIA...B6DW... (token present: Yes)
Testing immediately after extraction:
Using frozen credentials from earlier
Failed with error: An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid.
Using credential provider chain
Success! Identity: arn:aws:sts::<MY_ACCOUNT>:assumed-role/myrole |
I've made some changes to make it less confusing
|
While reviewing the code, I noticed that our implementation for AWS credential handling might not work correctly with long-term AWS credentials (direct access/secret key pairs without session tokens). In the STT class's return TranscribeStreamingClient(
region=self._config.region,
credential_resolver=StaticCredentialResolver(
access_key_id=frozen_credentials.access_key,
secret_access_key=frozen_credentials.secret_key,
session_token=frozen_credentials.token, # This could be None with long-term credentials
),
) Long-term AWS credentials don't include a token component, which is only present when using temporary credentials from environment variables, IAM roles, or AWS STS. Suggested Fix resolver_args = {
"access_key_id": frozen_credentials.access_key,
"secret_access_key": frozen_credentials.secret_key,
}
if frozen_credentials.token:
resolver_args["session_token"] = frozen_credentials.token
return TranscribeStreamingClient(
region=self._config.region,
credential_resolver=StaticCredentialResolver(**resolver_args),
) This approach would ensure compatibility with both temporary and long-term credentials without requiring us to test every credential type directly. |
This will already be handled by |
LGTM for Livekit version |
Co-authored-by: Andor Markus <[email protected]>
…ekit#1849) Co-authored-by: Andor Markus <[email protected]>
clean up over pr #1837