1 Answer
- Newest
- Most votes
- Most comments
0
Hello @Mits,
Based on the error message you are seeing, it appears that there's an issue with permissions or access to the Bedrock model you are trying to use for embeddings.
Here are a few things to check and try:
- IAM Permissions: Make sure the IAM role or user associated with your application has the necessary permissions to invoke the Bedrock model. The required permission is typically bedrock:InvokeModel.
- Region Configuration: Ensure that your AWS SDK or Bedrock client is configured to use the correct region (eu-west-2 in your case). Sometimes, the client might default to a different region if not explicitly set.
- Model Access: Double-check that you have indeed been granted access to the specific model you are trying to use. Sometimes there can be a delay between granting access and it becoming effective.
- Model Availability: Verify that the model you are trying to use is available in the eu-west-2 region. Not all models are available in all regions.
- Quota Limits: Check if you have hit any quota limits for the Bedrock service in your AWS account.
- AWS CLI Test: Try invoking the model using the AWS CLI to see if you get the same error. This can help isolate whether it's a code issue or a permissions/access issue. aws bedrock invoke-model --model-id <your-model-id> --body '{"prompt": "Hello"}' --region eu-west-2
- Bedrock Console: Try accessing the model through the AWS Bedrock console to see if you can use it there.
- Check AWS CloudTrail: Look at CloudTrail logs to see if there are any more detailed error messages or access denied events related to your Bedrock invocations.
- Bedrock Client Configuration: If you're using a Bedrock client in your code, make sure it's properly configured with the correct credentials and region.
- Retry with Exponential Backoff: Sometimes these errors can be transient. Implement a retry mechanism with exponential backoff in your code.
answered 2 years ago
Relevant content
asked 3 years ago
- AWS OFFICIALUpdated a year ago

My code as follows import boto3 import streamlit as st import os import uuid
s3_client
s3_client = boto3.client("s3") BUCKET_NAME = os.getenv("BUCKET_NAME")
Bedrock
from langchain_community.embeddings import BedrockEmbeddings
Text Splitter
from langchain.text_splitter import RecursiveCharacterTextSplitter
Pdf Loader
from langchain_community.document_loaders import PyPDFLoader
import FAISS
from langchain_community.vectorstores import FAISS
bedrock_client = boto3.client(service_name="bedrock-runtime",region_name='eu-west-2') bedrock_embeddings = BedrockEmbeddings(model_id="amazon.titan-embed-text-v2:0", client=bedrock_client)
def get_unique_id(): return str(uuid.uuid4())
Split the pages / text into chunks
def split_text(pages, chunk_size, chunk_overlap): text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap) docs = text_splitter.split_documents(pages) return docs
create vector store
def create_vector_store(request_id, documents): print("1888888888888888888888888888") vectorstore_faiss=FAISS.from_documents(documents, bedrock_embeddings) print("9999999999999999999999") file_name=f"{request_id}.bin" print("1010101010101010101010101") folder_path="/tmp/" print("121212121212121212121212") vectorstore_faiss.save_local(index_name=file_name, folder_path=folder_path) print("13131313131313131313131313")