Introduction to Amazon Bedrock: Generative AI on AWS

Amazon Bedrock is a new, fully managed service that makes leading foundation models from AI startups and Amazon available via an API. Learn what it is and how to get started.

2023 has been the year of generative AI, and AWS has made its definitive entry into the space with the launch of Amazon Bedrock. Generally available as of September 2023, Bedrock is a fully managed service that offers a single, unified API to access a wide range of powerful foundation models (FMs) from leading AI companies.

Instead of having to integrate with multiple different APIs from various providers, Bedrock provides a single, secure, and serverless way to build generative AI applications on AWS.

What Problem Does Bedrock Solve?

Before Bedrock, if you wanted to experiment with different large language models, you would have to:

  • Sign up for separate accounts with each provider (OpenAI, Anthropic, Cohere, etc.).
  • Manage different API keys and SDKs for each service.
  • Worry about the security and privacy of sending your data to third-party APIs.

Bedrock simplifies all of this. It acts as a single gateway to a curated set of high-performing models, all within the security and privacy of your own AWS environment.

Key Features of Amazon Bedrock

  1. Choice of Leading Foundation Models: Bedrock provides access to a variety of models from top AI companies, including:

    • Anthropic: The Claude family of models, known for their strong safety features and conversational abilities.
    • AI21 Labs: The Jurassic-2 family, powerful multilingual models.
    • Stability AI: Including the popular Stable Diffusion model for text-to-image generation.
    • Cohere: Powerful models focused on enterprise use cases.
    • Amazon: The Amazon Titan family of models, developed by AWS.

    This allows you to choose the best model for your specific use case without being locked into a single provider.

  2. Serverless API: You interact with these models through a simple, unified API. There are no servers to manage, and you only pay for what you use (typically based on the number of input and output tokens).

  3. Security and Privacy: A major selling point for enterprises. Your data is never used to train the base models, and all data is encrypted in transit and at rest. You can use standard AWS security controls, like IAM and VPC endpoints, to secure your Bedrock usage.

  4. Customization with Your Own Data: Bedrock allows you to privately fine-tune the foundation models with your own labeled datasets. This enables you to create a model that is an expert in your specific domain (e.g., a chatbot that understands your company's internal jargon) without having to build a model from scratch.

Getting Started with Bedrock

Using Bedrock is straightforward, especially with the AWS SDK for Python (Boto3).

First, you need to enable model access in the Bedrock console. Once that's done, you can invoke a model with a few lines of code.

Example: Invoking Anthropic's Claude 2 with Boto3

import boto3
import json

# Create a Bedrock client
bedrock_runtime = boto3.client(service_name='bedrock-runtime', region_name='us-east-1')

# Define the prompt
prompt = "\n\nHuman: What is the largest planet in our solar system?\n\nAssistant:"

# Prepare the request body
body = json.dumps({
    "prompt": prompt,
    "max_tokens_to_sample": 300,
    "temperature": 0.7,
})

# The model ID for Claude 2
model_id = 'anthropic.claude-v2'

# Invoke the model
response = bedrock_runtime.invoke_model(
    body=body, 
    modelId=model_id, 
    accept='application/json', 
    contentType='application/json'
)

# Parse the response
response_body = json.loads(response.get('body').read())
completion = response_body.get('completion')

print(completion)

This code sends a prompt to the Claude 2 model via the Bedrock API and prints the response. The process is similar for all other models available in Bedrock; you just change the modelId and the structure of the body to match the provider's specific format.

Conclusion

Amazon Bedrock is a powerful and strategic service that democratizes access to generative AI for developers already in the AWS ecosystem. By providing a secure, serverless, and unified way to access a diverse range of leading foundation models, it dramatically lowers the barrier to entry for building sophisticated AI-powered applications. For any organization looking to leverage generative AI on AWS, Bedrock is the clear and compelling place to start.