Skip to content
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

[Bug]: AWS region name error when passing user bedrock client #1292

Closed
dleen opened this issue Jan 1, 2024 · 7 comments
Closed

[Bug]: AWS region name error when passing user bedrock client #1292

dleen opened this issue Jan 1, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@dleen
Copy link
Contributor

dleen commented Jan 1, 2024

What happened?

First, thanks for this great project!

When passing my own bedrock client:

def get_bedrock_client():
    return boto3.client(
        "bedrock-runtime",
        region_name="us-east-1",
        # ...keys etc...
    )

completion(
    ...
    aws_bedrock_client=get_bedrock_client(),
    ...

I get the error:

BedrockException - AWS region not set: set AWS_REGION_NAME or AWS_REGION env variable or in .env file

adding:

completion(
    ...
    aws_bedrock_client=get_bedrock_client(),
    aws_region_name="us-east-1",
    ...

fixes the issue but obviously should not be needed since the client defines the region.

It seems like the issue is due to a function call being used as the default value when calling pop on the optional params dict. Maybe the assumption is that the default value is not evaluated unless needed? But the function is being called regardless if the default is used or not.

My suggestion for a fix is to just call pop without a default and then examine it for None and then call the function. I'll make this change if you agree with the approach.

Relevant log output

No response

Twitter / LinkedIn details

No response

@dleen dleen added the bug Something isn't working label Jan 1, 2024
@ishaan-jaff
Copy link
Contributor

@dleen fix is here: d1e8d13

Before closing this issue, I will

  • Add testing for this scenario
  • Make the same changes for Sagemaker
  • push a new release on pypi

Thanks for the issue, I reached out on Linkedin to set up a direct support channel too

@ishaan-jaff ishaan-jaff self-assigned this Jan 1, 2024
@dleen
Copy link
Contributor Author

dleen commented Jan 1, 2024

Nice!

@krrishdholakia
Copy link
Contributor

will close once we have a release out

@ishaan-jaff
Copy link
Contributor

ishaan-jaff commented Jan 2, 2024

I can repro this error with our test too, needed to update our test for this scenario

LiteLLM.Info: If you need to debug this error, use `litellm.set_verbose=True'.

Traceback (most recent call last):
  File "/Users/ishaanjaffer/Github/litellm/litellm/main.py", line 1429, in completion
    response = bedrock.completion(
  File "/Users/ishaanjaffer/Github/litellm/litellm/llms/bedrock.py", line 641, in completion
    raise e
  File "/Users/ishaanjaffer/Github/litellm/litellm/llms/bedrock.py", line 427, in completion
    client = optional_params.pop("aws_bedrock_client", init_bedrock_client(
  File "/Users/ishaanjaffer/Github/litellm/litellm/llms/bedrock.py", line 325, in init_bedrock_client
    raise BedrockError(
litellm.llms.bedrock.BedrockError: AWS region not set: set AWS_REGION_NAME or AWS_REGION env variable or in .env file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/ishaanjaffer/Github/litellm/litellm/tests/test_completion.py", line 1552, in test_completion_bedrock_claude_external_client_auth
    response = completion(
  File "/Users/ishaanjaffer/Github/litellm/litellm/utils.py", line 2113, in wrapper
    raise e
  File "/Users/ishaanjaffer/Github/litellm/litellm/utils.py", line 2020, in wrapper
    result = original_function(*args, **kwargs)
  File "/Users/ishaanjaffer/Github/litellm/litellm/main.py", line 1743, in completion
    raise exception_type(
  File "/Users/ishaanjaffer/Github/litellm/litellm/utils.py", line 6375, in exception_type
    raise e
  File "/Users/ishaanjaffer/Github/litellm/litellm/utils.py", line 5629, in exception_type
    raise AuthenticationError(
litellm.exceptions.AuthenticationError: BedrockException - AWS region not set: set AWS_REGION_NAME or AWS_REGION env variable or in .env file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/ishaanjaffer/Github/litellm/litellm/tests/test_completion.py", line 1569, in <module>
    test_completion_bedrock_claude_external_client_auth()
  File "/Users/ishaanjaffer/Github/litellm/litellm/tests/test_completion.py", line 1568, in test_completion_bedrock_claude_external_client_auth
    pytest.fail(f"Error occurred: {e}")
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_pytest/outcomes.py", line 198, in fail
    raise Failed(msg=reason, pytrace=pytrace)
Failed: Error occurred: BedrockException - AWS region not set: set AWS_REGION_NAME or AWS_REGION env variable or in .env file

@ishaan-jaff
Copy link
Contributor

testing for bedrock here too now: 18ef244

We test passing the boto3 client

@ishaan-jaff
Copy link
Contributor

will close this issue once we have a new deploy

@ishaan-jaff
Copy link
Contributor

Fixed in litellm 1.16.9+

@dleen closing this issue, feel free to re-open if not fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants