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

Issues with README instructions not working #1

Closed
davetbo-amzn opened this issue Jul 17, 2023 · 4 comments
Closed

Issues with README instructions not working #1

davetbo-amzn opened this issue Jul 17, 2023 · 4 comments

Comments

@davetbo-amzn
Copy link

I'm running the instructions in README.md in a new python3.9 venv. I downloaded the dependencies and successfully ran the 3 pip install statements for boto3, botocore, and awscli. When I try to create the client as instructed with this code:

import boto3
print ('boto3 version:\n', boto3.__version__)
bedrock = boto3.client('bedrock', region_name='us-east-1')

I get this output and error (note I added the version print).

 amazon-bedrock-workshop]$ python3 test_client.py 
boto3 version:
 1.26.162
Traceback (most recent call last):
  File "/workplace/amazon-bedrock-workshop/test_client.py", line 3, in <module>
    bedrock = boto3.client('bedrock', region_name='us-east-1')
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/boto3/__init__.py", line 92, in client
    return _get_default_session().client(*args, **kwargs)
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/boto3/session.py", line 299, in client
    return self._session.create_client(
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/botocore/session.py", line 976, in create_client
    client = client_creator.create_client(
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/botocore/client.py", line 126, in create_client
    service_model = self._load_service_model(service_name, api_version)
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/botocore/client.py", line 228, in _load_service_model
    json_model = self._loader.load_service_model(
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/botocore/loaders.py", line 142, in _wrapper
    data = func(self, *args, **kwargs)
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/botocore/loaders.py", line 408, in load_service_model
    raise UnknownServiceError(
botocore.exceptions.UnknownServiceError: Unknown service: 'bedrock'. Valid service names are: accessanalyzer,...  <truncated>

If I try to use the bedrock client in the utils directory instead by importing utils.bedrock in a python3 interactive session it complains that I need to install pydantic:

  File "/workplace/amazon-bedrock-workshop/utils/bedrock.py", line 5, in <module>
    from pydantic import root_validator
ModuleNotFoundError: No module named 'pydantic'

so I install it:

pip3 install pydantic

and it installed version 2.0.3. Then I tried again to import it and got a new error:

>>> import utils.bedrock
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/workplace/amazon-bedrock-workshop/utils/bedrock.py", line 66, in <module>
    class Bedrock:
  File "/workplace/amazon-bedrock-workshop/utils/bedrock.py", line 80, in Bedrock
    @root_validator()
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/pydantic/deprecated/class_validators.py", line 228, in root_validator
    raise PydanticUserError(
pydantic.errors.PydanticUserError: If you use `@root_validator` with pre=False (the default) you MUST specify `skip_on_failure=True`. Note that `@root_validator` is deprecated and should be replaced with `@model_validator`.

For further information visit https://errors.pydantic.dev/2.0.3/u/root-validator-pre-skip

If I change line 80 to look like this, that error goes away:

    @root_validator(skip_on_failure=True)

Then if I try to use the get_bedrock_client in that function, I'm back to the error where it doesn't recognize bedrock:

>>> import utils.bedrock
>>> bedrock = utils.bedrock.get_bedrock_client()
Create new client
  Using region: us-east-1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/workplace/amazon-bedrock-workshop/utils/bedrock.py", line 46, in get_bedrock_client
    bedrock_client = session.client(
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/boto3/session.py", line 299, in client
    return self._session.create_client(
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/botocore/session.py", line 976, in create_client
    client = client_creator.create_client(
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/botocore/client.py", line 126, in create_client
    service_model = self._load_service_model(service_name, api_version)
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/botocore/client.py", line 228, in _load_service_model
    json_model = self._loader.load_service_model(
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/botocore/loaders.py", line 142, in _wrapper
    data = func(self, *args, **kwargs)
  File "/workplace/amazon-bedrock-workshop/.venv/lib/python3.9/site-packages/botocore/loaders.py", line 408, in load_service_model
    raise UnknownServiceError(
botocore.exceptions.UnknownServiceError: Unknown service: 'bedrock'. Valid service names are: accessanalyzer...<truncated>

So it looks like the versions of boto3 being downloaded by download_dependencies.sh are not working. Any advice would be appreciated.

@davetbo-amzn
Copy link
Author

I should note I'm trying to do this from VSCode this time. I previously got this working in SageMaker Studio with an earlier patched version of the boto3 and botocore modules. I'll go try Studio again and see if it helps.

@davetbo-amzn
Copy link
Author

I just got it working in SageMaker Studio, so it must be something different in the environment.

@tchattha
Copy link
Contributor

Fixed the issue and marked the correct kernel type to use in SageMaker Studio.
Also added comments in the README to use conda environment.
Re-open the issue if you think it still persists.

@rmartine-ias
Copy link

Still encountering the following issues:

  • pydantic install requirement is not documented (no string "conda" found in repo)
  • on L106 of utils/bedrock.py: pydantic.errors.PydanticUserError: If you use @root_validator with pre=False (the default) you MUST specify skip_on_failure=True. Note that @root_validator is deprecated and should be replaced with @model_validator.

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

No branches or pull requests

3 participants