-
Notifications
You must be signed in to change notification settings - Fork 315
feat(bedrock): automatically infer AWS Region in Bedrock clients #974
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
feat(bedrock): automatically infer AWS Region in Bedrock clients #974
Conversation
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.
This overall LGTM @karpetrosyan! Could we just remove the workflow change before merging?
.github/workflows/ci.yml
Outdated
@@ -7,6 +7,8 @@ on: | |||
- 'integrated/**' | |||
- 'stl-preview-head/**' | |||
- 'stl-preview-base/**' | |||
pull_request: |
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.
mind removing this before merging?
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.
yes, sure!
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.
done
@dtmeadows fyi, seems like I can't merge this |
@michael-cohen-io mind reviewing and merging this when you get a sec? |
…o karpetrosyanpy/sdk-2760-anthropic-python-correctly-infer-bedrock-region-from-aws
try: | ||
import boto3 | ||
|
||
session = boto3.Session() |
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.
actually do you know if this can make fs calls?
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.
I don't fully understand what 'making fs calls' means. It has access to the standard library, which I assume it uses to read the AWS config file.
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.
ah sorry, yeah I meant "does it call blocking IO functions" which if it does we should try and call it asynchronously...
but that might be difficult?
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.
It definitely does, but I think it's okay. It won't block the event loop repeatedly—just once during initialization
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.
users may instantiate the client in their business logic inside async functions so I think it is somewhat important unfortunately.
if wrapping this in async is too annoying, I think for now we could cache the boto3.Session
object?
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.
if wrapping this in async is too annoying, I think for now we could cache the boto3.Session object?
In that case, users with an async codebase will still be blocked the first time they call it — am I getting that right? Honestly, I don't think it's worth doing anything about. Many clients block for a few milliseconds during initialization. For example, httpx.AsyncClient
takes around 50-150ms
to create (which means the event loop is blocked for that time), while boto3.Session()
blocks for just 5ms. Programmers should avoid creating such objects inside a (for/while) loop — that would kill performance anyway (they're supposed to be created once). So if it's done only once, is a 5ms delay really that critical?
you can check setup time with this script:
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "boto3",
# "httpx",
# ]
# ///
import boto3
import time
import httpx
t1 = time.monotonic_ns()
boto3.Session()
t2 = time.monotonic_ns()
print(f"boto3 Time taken: {(t2 - t1) / 1_000_000} ms")
t1 = time.monotonic_ns()
httpx.Client()
t2 = time.monotonic_ns()
print(f"httpx Time taken: {(t2 - t1) / 1_000_000} ms")
closes #892 and #537