Mastering Amazon Bedrock with Claude 3: Developer's Guide with Demos

Mastering Amazon Bedrock with Claude 3: Developer's Guide with Demos

Unleash the power of AI in your business with the Claude 3 family, now on Amazon Bedrock. These intelligent, fast, and cost-effective models tackle a wide range of tasks, perfectly suited for your needs. Demos showcased Claude 3's versatility: identify circuit board defects, easily compare model options, and leverage Claude 3 as your coding advisor, generating commented code based on your prompts. Code samples are included to streamline your journey with Claude 3 and Amazon Bedrock APIs.

Haowen Huang
Amazon Employee
Published Apr 27, 2024
Last Modified Apr 28, 2024
The rise of generative AI has brought incredible potential with large language models. But as the saying goes, "seeing is believing." In this post, we'll showcase the magic of Claude 3, a cutting-edge foundation model, through real-world demos that demonstrate its impact on your daily life and work.

The Power of Choice: Claude 3 Model Family

First, we'll take a closer look at the Claude 3 model family.
Generative AI isn't a one-size-fits-all solution. Through customer conversations over the past year, we've identified diverse enterprise use cases. These cases require a balance between model intelligence, speed, and quality, but the priority for each case is different.
For instance, a chatbot prioritizes low latency over cutting-edge intelligence. Conversely, advanced analytics require superior intelligence even if it means sacrificing some speed. Therefore, enterprises deploying AI solutions need a flexible range of models to address these diverse needs.
Anthropic's Claude 3 family offers state-of-the-art AI models (Haiku, Sonnet, Opus) available on Amazon Bedrock. Each option balances intelligence and cost for your specific business needs. Shown as below.
Anthropic's Claude 3 family
Anthropic's Claude 3 family: Haiku, Sonnet, Opus
Source: https://www.anthropic.com/news/claude-3-family
  • Claude 3 Opus: The powerhouse, optimized for maximum intelligence and ideal for complex tasks.
  • Claude 3 Haiku: The lightweight and cost-effective model, prioritizing speed and efficiency while retaining significant intelligence.
  • Claude 3 Sonnet: The perfect balance, offering a blend of cost, speed, and intelligence, for a wide range of applications.
Claude 3 raises the bar with vision capabilities built into every model. This let them analyze images, diagrams, and reports – even faster than some specialized models – without sacrificing their overall performance. We’ll see this powerful multimodal ability in action during the next demo.

Claude 3 in Action

We'll explore several impressive applications built using Claude 3 on Amazon Bedrock. We'll explore a mix of demos: some leveraging the interactive AWS console interface, and others harnessing the raw power of Amazon Bedrock's API through direct Claude 3 model calls.

Demo #1: Circuit Board Defect Detection (Sonnet)

Get ready to be impressed! Our first demo tackles circuit board defect detection in an industrial environment. This powerful demo showcases how Claude 3, running on Amazon Bedrock, can identify defects on circuit boards. We'll delve deeper into the process with the following three images.
The following images provide a reference for common circuit board defects:
  • Left: This image illustrates common circuit board defects.
  • Center: This image shows a normal, defect-free circuit board.
  • Right: This image displays a circuit board with several defects.
Images for Circuit Board Defect Detection
Images for Circuit Board Defect Detection
Now, let's see Claude 3 in action! We'll use the following prompt to query the Sonnet model, simulating a professional circuit board design engineer:
Given the role of a professional circuit board design engineer, analyze the attached images for defects. Here's a breakdown of the task:
  1. Image 1: Identify and describe the types and specific examples of defects present.
  2. Image 2 & 3: Determine if there are any flaws in these circuit boards. If so, pinpoint the specific defects in each image.
By combining these images and the text prompt, we create a comprehensive query for Claude 3 Sonnet. This will allow the model to generate the desired output, which we'll see in the following screenshot.
Combining three images and the text prompt
Combining three images and the text prompt
Our tests revealed that the Haiku model is much faster, processing images in just seven seconds compared to Sonnet's ten seconds. However, precision remains paramount in tasks like circuit board inspection. Sonnet's ability to detect the subtle flaw in image #3 exemplifies this. For complex tasks requiring high accuracy, Sonnet's superior detection capabilities outweigh Haiku's speed benefit.
Watch the full demo here:

Demo #2: Circuit Board Defect Detection (Sonnet vs. Haiku)

In this demo, we’ll compare two Claude 3 models, Sonnet and Haiku, on the same circuit board defect detection task.
  1. Select the Anthropic Sonnet model on the left side of the Chat Playground.
  2. Click the "Compare Mode" button (top right corner) and choose the Haiku model.
Comapre mode on Amazon Bedrock Playground
Comapre mode on Amazon Bedrock Playground
This will display both models side-by-side in the interface.
Amazon Bedrock Compare Mode - Sonnet vs. Haiku
Amazon Bedrock Compare Mode - Sonnet vs. Haiku
The Haiku model completed the task in just 7 seconds, compared to Sonnet’s 10 seconds. While Haiku is faster, let’s see how accuracy compares.
Taking a closer look at Haiku’s output, we see it missed the flaw in image #3. Sonnet, though slower, correctly identified the flaw again.
For complex tasks like circuit board defects detection, Sonnet’s ability to solve real-world problems seems superior. This demo showcases the trade-off between speed and accuracy in model comparison.
One key benefit of Amazon Bedrock’s “Compare mode” is the ease of comparing outputs from different models. With a single switch, developers can efficiently evaluate model performance.
Watch the full demo here:

Demo #3: Claude 3 as Your Coding Advisor (Sonnet)

Demo #3 showcases the Claude 3 model working as a coding advisor.
Are you a beginner in machine learning? Have you been devouring books and documentation, eager to get your hands dirty? Demo #3 showcases Claude 3 as your coding advisor, guiding you through building a convolutional neural network (CNN) from scratch!
The following prompt will be used:
Please implement a convolutional neural network from scratch using Python. Finally, give an example of how to use the implemented CNN and sample values as input to predict the output of the model. Since these codes are for beginners, please try to meet the following conditions:
1/ Provide detailed code comments
2/ Draw a structural diagram of the layers of the convolutional neural network you designed
Before unleashing Claude 3, a crucial step! Since this model can generate lengthy responses, navigate to the “Configurations” section on the right. Locate the “Length” parameter and set it to its maximum value (4096). This may let you capture the entire response.
Configurations - Length - Maximum Length Setting
Configurations - Length - Maximum Length Setting
Want to see the full demo? Check out this demo on YouTube!
This demo is just a glimpse of Claude 3’s code generation capabilities! Intrigued by its ability to write code? You might be wondering if the generated code can actually run. The answer is promising!
In my experience, with some refinement, Claude 3 can generate functional code. While the initial output might have minor errors, interacting with Claude 3 iteratively can help achieve a complete and accurate solution.

Beyond the Console: Exploring the Amazon Bedrock API

The demos we explored utilized the Amazon Bedrock console to showcase the capabilities of the Claude 3 model. But there’s another way! The Bedrock API offers programmatic access, opening up new possibilities.
The Anthropic website provides an excellent example, demonstrating how to use “Claude 3 with Amazon Bedrock APIs” in just 10 lines of code. This intuitive approach inspired me to leverage the same code snippet to write a 300-word novel in the style of Shakespeare!
The full Python code is here. Surprisingly simple code can call the Amazon Bedrock API!
import boto3
import json

bedrock = boto3.client(service_name="bedrock-runtime")

body = json.dumps({
"max_tokens": 256,
"messages": [{"role": "user", "content": "Please write a 300-word short story in the style of Shakespeare"}],
"anthropic_version": "bedrock-2023-05-31"

response = bedrock.invoke_model(body=body, modelId="anthropic.claude-3-sonnet-20240229-v1:0")
response_body = json.loads(response.get("body").read())


Demo #4: Quantifying Performance: Haiku vs. Sonnet with Amazon Bedrock APIs

Compared to the Playground mode, the Amazon Bedrock API provides a more objective way to interact with the Claude 3 model and get results.
In Demo #2, we subjectively judged Haiku to be faster than Sonnet when comparing their perceived response speed. The Amazon Bedrock API offers a data-driven solution.
By using the Amazon Bedrock API to call Claude 3, we can capture key metrics like invocationLatency and firstByteLatency, allowing for a precise comparison of Haiku and Sonnet’s performance.
The following is the output of the Claude 3 Haiku Model:
{'amazon-bedrock-invocationMetrics': {'firstByteLatency': 514,
'inputTokenCount': 489,
'invocationLatency': 2038,
'outputTokenCount': 141},
'type': 'message_stop'}
The following is the output of the Claude 3 Sonnet Model:
{'amazon-bedrock-invocationMetrics': {'firstByteLatency': 538,
'inputTokenCount': 443,
'invocationLatency': 5258,
'outputTokenCount': 169},
'type': 'message_stop'}
Want to delve deeper? Explore the full code here:
And see the video illustration here:


The Claude 3 family of models, now available on Amazon Bedrock, offers a powerful and versatile AI solution for businesses. These models strike a remarkable balance between intelligence, speed, and cost, making them ideal for diverse business needs.
We explored Claude 3's capabilities through these impressive demos:
  • Detect circuit board defects: Pinpoint and detail circuit board defects with image analysis prowess.
  • Model compare mode: Compare Claude 3 models (Sonnet vs. Haiku) with Compare Mode
  • Coding advisor: Claude 3 acts as your coding advisor, generating commented and explained code from your prompts.
We even provided code samples to jumpstart your exploration of using Claude 3 with Amazon Bedrock APIs.
Claude 3's ability to understand and process diverse data, generate code, and adapt outputs to specific needs makes it truly ground-breaking. This has the potential to revolutionize AI applications across numerous industries.
Intrigued by Claude 3's potential to transform your workflows? Dive deeper! Explore how large language models (LLMs) can empower your daily work. Get started with Claude 3 in Amazon Bedrock using the provided documentation:
I'm excited to see the innovative applications you'll build with Claude 3!

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.