430.00 b

Description: Using Langchain, Implement RAG from AWS Bedrock

#400#ML_Engineer_Basic#430#ML_Development_Tools#430.00#LangChain#430.00 a#Langchain_Components#430.00 b#Amazon_Bedrock_with_RAG

01 access denined on model call from intro boto3 setup
03QuestioinAnswering

전부 주석처리 그대로해서 디폴트값 사용
# os.environ["AWS_DEFAULT_REGION"] = "<REGION_NAME>"  # E.g. "us-east-1"
# os.environ["AWS_PROFILE"] = "<YOUR_PROFILE>"
# os.environ["BEDROCK_ASSUME_ROLE"] = "<YOUR_ROLE_ARN>"  # E.g. "arn:aws:..."

accesdenined on function call

try:
    
    sample_embedding = np.array(bedrock_embeddings.embed_query(docs[0].page_content))
    print("Sample embedding of a document chunk: ", sample_embedding)
    print("Size of the embedding: ", sample_embedding.shape)

except ValueError as error:
    if  "AccessDeniedException" in str(error):
        print(f"\x1b[41m{error}\
        \nTo troubeshoot this issue please refer to the following resources.\
         \nhttps://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_access-denied.html\
         \nhttps://docs.aws.amazon.com/bedrock/latest/userguide/security-iam.html\x1b[0m\n")      
        class StopExecution(ValueError):
            def _render_traceback_(self):
                pass
        raise StopExecution        
    else:
        raise error

Checking sagemaker iam role, default sagemaker user role has no bedrock related policies.
grant bedrock fullaccess
->still get access error

Looking again, I see that the first sagemaker image mentions data science 3.0 image conditions.
Navigated to the ECR image domain to use that image. so I could download it directly to my sagemaker environment.
But couldn't find it

so thought of creating ecr and uploading it myself
So I tried sagemaker sdk, but it doesn't show the domain if I use url

I thought about using a Jupyter instance, but it doesn't have a linkchain.

Translated with www.DeepL.com/Translator (free version)


Solved
Allow model access in the console first
Add that setting when you want to use it locally

ACCESS_KEY = '' ## aws ACCESS_KEY 입력
SECRET_KEY = 'secrt key'

os.environ["AWS_DEFAULT_REGION"] = "us-east-1"

bedrock_runtime = boto3.client('bedrock-runtime',
region_name = 'us-east-1',
endpoint_url="https://bedrock-runtime.us-east-1.amazonaws.com",
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
)
titan = 'amazon.titan-embed-text-v1'

bedrock_embeddings = BedrockEmbeddings(model_id=titan,
region_name = 'us-east-1',
client=bedrock_runtime
)