aws-samples / amazon-bedrock-workshop

This is a workshop designed for Amazon Bedrock a foundational model service.
https://catalog.us-east-1.prod.workshops.aws/workshops/a4bdb007-5600-4368-81c5-ff5b4154f518/en-US/20-intro
MIT No Attribution
1.42k stars 607 forks source link

Amazon Bedrock Workshop - [Bug] 02_qa_w_rag_claude_opensearch.ipynb hardcoded to use us-east-1 #248

Open jicowan opened 5 months ago

jicowan commented 5 months ago

Describe the bug The following code in 02_qa_w_rag_claude_opensearch.ipynb will throw an error if the AWS_DEFAULT_REGION is not set. Update to retrieve the region dynamically, e.g. boto3.session.Session.region_name. Do not hard code the region.

from opensearchpy import OpenSearch, RequestsHttpConnection, AWSV4SignerAuth
from langchain.vectorstores import OpenSearchVectorSearch

service = 'aoss'
credentials = boto3.Session().get_credentials()
auth = AWSV4SignerAuth(credentials, os.environ.get("AWS_DEFAULT_REGION", 'us-east-1'), service)

The following line in 02_qa_w_rag_claude_opensearch.ipynb will also throw an error if the REGION is not set:

host = collection['createCollectionDetail']['id'] + '.' + os.environ.get("AWS_DEFAULT_REGION", None) + '.aoss.amazonaws.com:443'

None is not an appropriate value if the variable is not set.

w601sxs commented 4 months ago

I agree, can you do a quick PR @jicowan ? Thank you for catching this and improving our examples