Enterprise DNA

Omni by Enterprise DNA

Enterprise DNA Resources

Step-by-step how-tos. Practical AI operating-system thinking for owners, operators, and teams doing real work.

220k+

Data professionals

Omni

AI agents and apps

Audit

Map the manual work

Guide Intermediate General

AWS Bedrock tutorial: setup Claude from scratch

A practical walkthrough of AWS Bedrock covering setup, authentication, your first Claude API call, key parameters, and where Bedrock fits in real workflows.

Sam McKay |
AWS Bedrock tutorial: setup Claude from scratch

What AWS Bedrock actually is

AWS Bedrock is a managed service from Amazon that gives you API access to foundation models from multiple providers without you having to host the models yourself. The technical reality is that Bedrock sits as a unified inference layer between your application and models like Anthropic’s Claude, Meta’s Llama, Mistral, AI21’s Jurassic, Amazon’s own Titan, and Stability AI’s image models.

Under the hood, Bedrock handles the GPU provisioning, model loading, scaling, and inference routing. You send a request with a prompt and parameters, you get a response back. The interesting part is that the request format is largely consistent across providers, so switching from Claude to Llama to Titan is mostly a matter of changing a model ID rather than rewriting your integration code.

This matters because most teams that want to use Claude end up going directly to Anthropic’s API. Bedrock is the alternative path, and it has specific tradeoffs. You’re routing through AWS, which means IAM, CloudWatch, VPC endpoints, and consolidated billing. If your stack is already on AWS, that’s a significant advantage. If it’s not, you’re adding a dependency for marginal benefit.

Bedrock also offers a few features beyond raw inference. There’s a Knowledge Base feature that handles RAG with vector storage, Agents that can orchestrate multi-step tool use, Fine-tuning for certain models, and Custom Model Import which lets you bring your own weights. The current version of these features varies, and AWS adds new capabilities regularly.

The honest framing: Bedrock is a model marketplace and inference gateway with some orchestration tools bolted on. It’s not a complete AI platform, but the inference layer is solid and the AWS integration is genuinely useful if you’re already in that ecosystem.

Setup and authentication

The setup path depends on whether you’re working in the AWS console or programmatically. You’ll likely use both at different stages.

Console setup starts with signing in to AWS using an account that has IAM permissions to create roles and enable services. Navigate to the Bedrock console, typically found under the Machine Learning category. In the current version of the console, you’ll see a Model access panel on the left sidebar. Click Manage model access and request access to the models you want. Claude models require Anthropic to grant access, which usually happens within minutes for standard accounts. Once access is granted, you can test models directly in the playground before writing any code.

Programmatic setup requires the AWS CLI configured with credentials that have bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream permissions at minimum. Install the AWS CLI if you haven’t already, then run aws configure. You’ll be prompted for an access key, secret key, default region, and output format. Use a region where Bedrock is available, such as us-east-1 or us-west-2.

For Python, install the boto3 library with pip install boto3. Then verify your setup by listing available models using aws bedrock list-foundation-models —region us-east-1. If this returns a JSON list of models, you’re authenticated and ready to go. If you get an access denied error, your IAM policy needs adjustment.

For production setups, use IAM roles rather than long-lived access keys. If you’re running on EC2, Lambda, or ECS, attach a role with the necessary Bedrock permissions to the compute resource. This is the standard AWS pattern and avoids the security risk of embedded credentials.

First working example

Here’s a complete, runnable Python example that sends a prompt to Claude via Bedrock.

import boto3 import json

client = boto3.client( service_name=“bedrock-runtime”, region_name=“us-east-1” )

body = json.dumps({ “anthropic_version”: “bedrock-2023-05-31”, “max_tokens”: 1024, “messages”: [ { “role”: “user”, “content”: “Explain the difference between RAG and fine-tuning in three sentences.” } ] })

response = client.invoke_model( modelId=“anthropic.claude-3-sonnet-20240229-v1:0”, body=body, contentType=“application/json”, accept=“application/json” )

response_body = json.loads(response.get(“body”).read()) print(response_body[“content”][0][“text”])

A few things to note about this code. The model ID format is provider.model-name-version. The anthropic_version field is required for Claude models and tells Bedrock which API schema to use. The messages array follows the standard chat format with role and content fields.

When you run this, you’ll get Claude’s response printed to your terminal. If you get a ValidationException, check that the model ID is correct for your region. If you get an AccessDeniedException, your IAM permissions need adjustment.

For streaming responses, use invoke_model_with_response_stream instead. This returns chunks as they’re generated, which is what you want for chat interfaces where perceived latency matters. The streaming pattern involves iterating over response.get(“body”) and processing each chunk.

The response structure for Claude includes a content array with text blocks, a stop_reason field, and usage statistics showing input and output token counts. Parse these for cost tracking and observability.

Key settings that matter

Most users only touch max_tokens and temperature, but Bedrock exposes several parameters that meaningfully change behavior.

Temperature controls randomness. Values range from 0 to 1 for Claude models. Lower values make outputs more deterministic, higher values introduce more variation. For factual tasks like extraction or classification, keep it low. For creative tasks, push it higher.

Top_p is the nucleus sampling parameter. It controls the cumulative probability mass from which tokens are sampled. Most users don’t need to touch this, but if you’re getting repetitive outputs at higher temperatures, lowering top_p can help.

Max_tokens caps the response length. Set this based on your use case. A short classification might only need 50 tokens. A long-form generation might need 4000 or more. Be aware that output tokens are billed, so don’t set this higher than you need.

Stop sequences let you specify strings that, when generated, will halt the response. Useful for structured outputs where you want the model to stop after a specific delimiter.

For Claude specifically, the system parameter lets you set a system prompt separately from the conversation. This is where you put behavioral instructions, persona definitions, or context that shouldn’t be part of the back-and-forth.

Inference profiles are a Bedrock-specific concept. They let you route requests across regions for latency optimization or to handle quota limits. If you’re hitting throughput limits, an inference profile can spread load.

Guardrails are another Bedrock feature worth understanding. You can configure content filters, denied topics, and sensitive information filters that apply across all model invocations. This is useful for compliance scenarios where you need consistent safety behavior regardless of which model is being called.

Where it shines

Bedrock excels in a few specific scenarios.

AWS-native architectures benefit most. If your infrastructure is already on AWS, Bedrock eliminates the need for separate API keys, separate billing, and separate observability for your AI layer. Everything flows through IAM and CloudWatch.

Multi-model strategies are easier to implement. The unified API means you can A/B test different models without rewriting integration code. Want to compare Claude’s performance against Llama on your specific task? Change the model ID and you’re done.

Compliance-heavy environments get useful features. Bedrock’s VPC endpoint support means you can keep inference traffic within your AWS network. Combined with guardrails and CloudWatch logging, this gives you the audit trail and network isolation that regulated industries require.

RAG with Knowledge Bases is faster to set up than building from scratch. The Knowledge Base feature handles the full pipeline: document ingestion, chunking, embedding, vector storage in OpenSearch or Pinecone, and retrieval-augmented generation. It’s not as flexible as building your own pipeline, but the time savings are real.

Agent orchestration handles multi-step workflows. Bedrock Agents can chain together model calls with tool use, allowing you to build workflows where the model decides which actions to take. This is useful for customer support automation, data analysis workflows, and similar multi-step tasks.

Consolidated billing simplifies procurement. If you’re already paying AWS a significant amount, adding Bedrock to the same bill often qualifies for enterprise discount programs and reduces vendor management overhead.

Where it fails

Bedrock has real limitations worth knowing before you commit.

Model freshness lags behind direct providers. AWS negotiates with providers to host models, and there’s typically a delay between when a new model releases and when it appears on Bedrock. If you need the absolute latest version of Claude or Llama, the direct API may have it first.

Pricing is competitive but