How to enable AWS Bedrock in console
Quick answer
To enable
AWS Bedrock in the AWS Management Console, sign in to your AWS account, navigate to the Bedrock service page, and accept the terms to activate it. Once enabled, you can access foundation models via the bedrock-runtime API or SDKs.PREREQUISITES
AWS account with permissions to enable servicesAWS CLI installed (optional for CLI usage)Python 3.8+boto3 installed (pip install boto3)
Setup
Before enabling AWS Bedrock, ensure you have an AWS account with appropriate permissions. You can optionally install the AWS CLI and boto3 Python SDK for programmatic access.
- Install AWS CLI:
https://aws.amazon.com/cli/ - Install boto3:
pip install boto3
pip install boto3 Step by step
To enable AWS Bedrock in the AWS Console:
- Sign in to the AWS Management Console.
- Search for and select
Bedrockin the Services menu. - On the Bedrock landing page, review and accept the terms and conditions to activate the service.
- Once enabled, you can start invoking foundation models via the
bedrock-runtimeAPI.
Example Python code to call a Bedrock model after enabling:
import os
import boto3
import json
# Initialize Bedrock runtime client
client = boto3.client('bedrock-runtime', region_name='us-east-1')
# Prepare messages for the model
messages = [{"role": "user", "content": [{"type": "text", "text": "Hello from AWS Bedrock!"}]}]
# Call the Bedrock model
response = client.converse(
modelId="anthropic.claude-3-5-sonnet-20241022-v2:0",
messages=messages
)
# Extract and print the response text
text = response['output']['message']['content'][0]['text']
print(text) output
Hello from AWS Bedrock! How can I assist you today?
Common variations
You can also invoke Bedrock models using the invoke_model method for raw JSON payloads. Additionally, you can enable Bedrock via AWS CLI once available, or use different foundation models by changing the modelId.
import boto3
import json
client = boto3.client('bedrock-runtime', region_name='us-east-1')
body = json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 512,
"messages": [{"role": "user", "content": "Explain quantum computing"}]
})
response = client.invoke_model(
modelId="anthropic.claude-3-5-sonnet-20241022-v2:0",
body=body
)
output = json.loads(response['body'])
print(output['output']['message']['content'][0]['text']) output
Quantum computing is a type of computation that uses quantum bits or qubits...
Troubleshooting
- If you cannot find
Bedrockin the AWS Console, verify your account region and permissions. - If API calls fail with authorization errors, ensure your IAM role has
bedrock-runtime:InvokeModelpermission. - Check that you are using the correct
region_namein your boto3 client.
Key Takeaways
- Enable AWS Bedrock by accepting terms in the AWS Management Console under the Bedrock service.
- Use boto3's bedrock-runtime client to invoke foundation models programmatically.
- Ensure IAM permissions and region settings are correct to avoid authorization errors.