Initializing AWS Bedrock
To interact with AWS Bedrock, we initialize the Bedrock runtime with your AWS profile and region. This setup is crucial for authenticating and directing our requests to the correct AWS services.
Jupyter Notebook Cell
# Set the AWS profile
# Replace 'your-profile-name' with your actual profile name
aws_profile = 'your-profile-name'
# Your region
aws_region_name = "us-east-1"
try:
boto3.setup_default_session(profile_name=aws_profile)
bedrock_runtime = boto3.client(
service_name="bedrock-runtime",
region_name=aws_region_name
)
except NoCredentialsError:
print("Credentials not found. Please configure your AWS profile.")
info
If you have only one AWS profile on your computer or you are using the default profile, you can omit the boto3.setup_default_session(profile_name=aws_profile) on line 6.
AWS SDKs automatically use the default profile if no profile is explicitly set. This simplifies the script and reduces the need for manual configuration
Let's prepare a made-up product catalog in the next section.