AWS Bedrock Quick Setup with Boto3

Rohan Ramesh
GenAI.io
Published in
3 min readMar 16, 2024

Amazon Web Services launched Amazon Bedrock , which has access to powerful Generative AI models from companies like AI21 Labs, Anthropic, Cohere, Meta, Mistral AI, etc. using a single API for each model with different modalities.

Bedrock is a fully managed service that makes foundation models (FMs) from leading AI companies available through a single application programming interface (API).

Foundation Models

If you have an existing AWS account, you can test them directly through their playground. You can navigate to the Model Access section to choose any desired model. Once you’ve confirmed your request, it may take a few minutes for model activation to complete.

Lets try to summarize a meeting transcript using one of the foundations model using AWS bedrock.

To access those models via a script we need to create an API.

IAM Configuration for API

First, we have to create an API user and assign the Bedrock role as a specific permission. We can use the Identity and Access Management service of AWS to create an API user.

Navigate to Services > IAM > Users > Create User

Set permission Bedrock full access

Navigate to Services > IAM > Users

Click on the newly created user and select the Security Credentials tab to create access keys.

For our Python scripts run locally, we select local code; for any other specific use case look into best IAM practices.

Copy or download the access key to a safe location.

Now the fun part.. !!

Boto3

Boto3 is the AWS SDK for Python. This makes it easy to integrate your Python application, library, or script with any AWS services. To use Boto3, we need the aws_secret_access_key and aws_access_key_id we configured in the previous step.

$ pip install boto3

AWS CLI

We can configure the keys using AWS CLI, refer the cli installation procedure based on your device here.

https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

Set the keys using the command-line interface.

$ aws configure

which is saved as a shared credential file (~/.aws/credentials) or AWS config file (~/.aws/config).

During program runtime, Boto3 will access these keys to initiate a request to the bedrock.

Code

Here is an example prompt for summarizing and extracting key takeaways from a meeting transcript using the Anthropic Claude 2 model.

There you have it.. a breakdown on how to initiate your initial API request to the latest Amazon Bedrock platform utilizing Anthropic Claude. In upcoming articles within this series, I’ll delve into integrating your unique data into the requests, enabling you to tailor a model to suit your specific use cases.

--

--