I am trying to call boto3 client bedrock (invoke_model or converse).
I am using boto3 1.35.35 and tried with 1.34.34.
I tried for the lambda function python 10, 11 and 12.
I already tried to pass the parameter endpoint_url with no effect.
The error happens when I try to create the client object.
code:
config = Config(
read_timeout=600, # 3 minutes in seconds
connect_timeout=600,
)
bedrock_clientConverse = boto3.client('bedrock-runtime',
aws_access_key_id=####",
aws_secret_access_key="######",
region_name='us-east-1',
config=config
)
This code works fine when I am calling from an EC2 instance that I have.
The lambda function has the same VPC/subnet/security groups as my EC2 instance.
The lambda role has all permissions to bedrock
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "bedrock:",
"Resource": [
"",
"*"
]
}
]
}
But I get the errors:
In the lambda execution panel:
{
"errorMessage": "Invalid endpoint: bedrock-runtime.us-east-1.amazonaws.com",
"errorType": "ValueError",
"requestId": "",
and in the cloudwatch log:
"invalid endpoint"
2024-10-13T15:38:35.593Z
INIT_START Runtime Version: python:3.12.v36 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:188d9ca2e2714ff5637bd2bbe06ceb81ec3bc408a0f277dab104c14cd814b081
2024-10-13T15:38:36.345Z
[DEBUG] 2024-10-13T15:38:36.345Z ++++++++++++++++++++++++++++++++++++++++
2024-10-13T15:38:36.346Z
[DEBUG] 2024-10-13T15:38:36.346Z Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2024-10-13T15:38:36.348Z
[DEBUG] 2024-10-13T15:38:36.348Z Changing event name from before-call.apigateway to before-call.api-gateway
2024-10-13T15:38:36.349Z
[DEBUG] 2024-10-13T15:38:36.349Z Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2024-10-13T15:38:36.351Z
[DEBUG] 2024-10-13T15:38:36.351Z Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2024-10-13T15:38:36.351Z
[DEBUG] 2024-10-13T15:38:36.351Z Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2024-10-13T15:38:36.352Z
[DEBUG] 2024-10-13T15:38:36.352Z Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2024-10-13T15:38:36.352Z
[DEBUG] 2024-10-13T15:38:36.352Z Changing event name from docs..autoscaling.CreateLaunchConfiguration.complete-section to docs..auto-scaling.CreateLaunchConfiguration.complete-section
2024-10-13T15:38:36.355Z
[DEBUG] 2024-10-13T15:38:36.355Z Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2024-10-13T15:38:36.355Z
[DEBUG] 2024-10-13T15:38:36.355Z Changing event name from docs..logs.CreateExportTask.complete-section to docs..cloudwatch-logs.CreateExportTask.complete-section
2024-10-13T15:38:36.355Z
[DEBUG] 2024-10-13T15:38:36.355Z Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2024-10-13T15:38:36.356Z
[DEBUG] 2024-10-13T15:38:36.356Z Changing event name from docs..cloudsearchdomain.Search.complete-section to docs..cloudsearch-domain.Search.complete-section
2024-10-13T15:38:36.367Z
[DEBUG] 2024-10-13T15:38:36.367Z Loading JSON file: /opt/python/botocore/data/endpoints.json
2024-10-13T15:38:36.394Z
[DEBUG] 2024-10-13T15:38:36.394Z Loading JSON file: /opt/python/botocore/data/sdk-default-configuration.json
2024-10-13T15:38:36.394Z
[DEBUG] 2024-10-13T15:38:36.394Z Event choose-service-name: calling handler <function handle_service_name_alias at 0x7f4c5fd8aa20>
2024-10-13T15:38:36.430Z
[DEBUG] 2024-10-13T15:38:36.430Z Loading JSON file: /opt/python/botocore/data/bedrock-runtime/2023-09-30/service-2.json.gz
2024-10-13T15:38:36.449Z
[DEBUG] 2024-10-13T15:38:36.449Z Loading JSON file: /opt/python/botocore/data/bedrock-runtime/2023-09-30/endpoint-rule-set-1.json.gz
2024-10-13T15:38:36.450Z
[DEBUG] 2024-10-13T15:38:36.450Z Loading JSON file: /opt/python/botocore/data/partitions.json
2024-10-13T15:38:36.451Z
[DEBUG] 2024-10-13T15:38:36.451Z Event creating-client-class.bedrock-runtime: calling handler <function add_generate_presigned_url at 0x7f4c5fc5bec0>
2024-10-13T15:38:36.451Z
[DEBUG] 2024-10-13T15:38:36.451Z Creating a regex based endpoint for bedrock-runtime, us-east-1
2024-10-13T15:38:36.455Z
[ERROR] ValueError: Invalid endpoint: bedrock-runtime.us-east-1.amazonaws.com
Traceback (most recent call last):
File "/var/lang/lib/python3.12/importlib/init.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/var/task/lambda_function.py", line 19, in <module>
bedrock_clientConverse = boto3.client('bedrock-runtime',
File "/opt/python/boto3/init.py", line 92, in client
return _get_default_session().client(*args, **kwargs)
File "/opt/python/boto3/session.py", line 297, in client
return self._session.create_client(
File "/opt/python/botocore/session.py", line 997, in create_client
client = client_creator.create_client(
File "/opt/python/botocore/client.py", line 165, in create_client
client_args = self._get_client_args(
File "/opt/python/botocore/client.py", line 524, in _get_client_args
return args_creator.get_client_args(
File "/opt/python/botocore/args.py", line 138, in get_client_args
endpoint = endpoint_creator.create_endpoint(
File "/opt/python/botocore/endpoint.py", line 408, in create_endpoint
raise ValueError(f"Invalid endpoint: {endpoint_url}")
[ERROR] ValueError: Invalid endpoint: bedrock-runtime.us-east-1.amazonaws.com Traceback (most recent call last): File "/va