Build Your First GenAI App in 10 Minutes with Amazon Bedrock and Python
Generative AI is one of the top trending topics across the AWS community, but many junior developers assume deploying foundation models requires expensive GPUs, deep PyTorch experience, or managing complex cluster infrastructure.
With Amazon Bedrock, you get serverless API access to leading foundation models (like Anthropic Claude, Amazon Titan, or Meta Llama) without provisioning a single server.
Here is a straightforward, beginner-friendly walkthrough to call your first foundation model using the AWS Python SDK (boto3).
Prerequisites
Prerequisites
- An AWS Account with configured credentials (aws configure).
Model access enabled:
- Open the Amazon Bedrock Console in a supported region (e.g., us-east-1).
- Select Model access on the left menu.
- Enable the model you want to test (for example, Amazon Titan Text G1 - Express or Claude 3.5 Sonnet).
Step 1: Install Dependencies
Set up a virtual environment and install boto3:
1
2
3
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install boto3Step 2: Use the Bedrock Converse API
AWS provides the unified Converse API (converse), which lets you interact with different foundation models using a standard format without writing model-specific request payloads.
Create bedrock_quickstart.py:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import boto3
from botocore.exceptions import ClientError
# Initialize the Bedrock Runtime client
bedrock = boto3.client(
service_name="bedrock-runtime",
region_name="us-east-1"
)
# Choose a model ID (Amazon Titan Text Express)
model_id = "amazon.titan-text-express-v1"
# Define your conversation payload
messages = [
{
"role": "user",
"content": [{"text": "Explain AWS IAM roles to a junior developer in 2 sentences."}]
}
]
try:
response = bedrock.converse(
modelId=model_id,
messages=messages,
inferenceConfig={"maxTokens": 100, "temperature": 0.5}
)
# Extract model output
output_text = response["output"]["message"]["content"][0]["text"]
print("Bedrock Response:\n")
print(output_text)
except ClientError as e:
print(f"Error invoking Bedrock: {e.response['Error']['Message']}")Step 3: Run and Test
Execute your script:
python bedrock_quickstart.pyYou will receive a response generated directly by the foundation model via AWS's secure, private API endpoint.
Why Bedrock is Great for New Cloud Developers
Why Bedrock is Great for New Cloud Developers
- No Idle Costs: You only pay per input/output token processed—no instances to remember to terminate.
- Enterprise Security: Your prompts and outputs stay inside your AWS boundary and are never used to train the base foundation models.
- Plug-and-Play Architecture: You can wrap this exact script inside an AWS Lambda function to power a serverless chatbot or documentation assistant.
Community Check-In
Builders: Have you started experimenting with Amazon Bedrock yet? Which foundation model has been your favorite to work with for everyday developer tasks? Let's discuss in the comments below!
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article