Set up AWS Bedrock client
Let's initialize Amazon Bedrock runtime client, this allows us to interact with AWS Titan to generate embeddings.
Set up AWS Bedrock client​
Add this code snippet to a new Jupyter Notebook cell, leave aws_profile
as None
to use your default AWS profile.
Jupyter Notebook
# Define your AWS profile
# Replace AWS_PROFILE with the name of your AWS CLI profile
# To use your default AWS profile, leave 'aws_profile' as None
aws_profile = os.environ.get('AWS_PROFILE')
# Specify the AWS region where Bedrock is available
aws_region_name = "us-east-1"
try:
# Set the default session for the specified profile
if aws_profile:
boto3.setup_default_session(profile_name=aws_profile)
else:
boto3.setup_default_session() # Use default AWS profile if none is specified
# Initialize the Bedrock runtime client
bedrock_runtime = boto3.client(
service_name="bedrock-runtime",
region_name=aws_region_name
)
except NoCredentialsError:
print("AWS credentials not found. Please configure your AWS profile.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
We're ready to generate embeddings in the next lesson.