DEV Community

Cover image for How to Build Your Own Claude Chat App on AWS Bedrock with AWS CDK (Beginner-Friendly Step-by-Step Guide)
Afu Tse (Chainiz)
Afu Tse (Chainiz)

Posted on

How to Build Your Own Claude Chat App on AWS Bedrock with AWS CDK (Beginner-Friendly Step-by-Step Guide)

🔗 Original article in Spanish:
“Crea tu propio chat con Claude en AWS Bedrock usando AWS CDK (guía paso a paso para principiantes)”
https://dev.to/chainiz/crea-tu-propio-chat-con-claude-en-aws-bedrock-usando-aws-cdk-guia-paso-a-paso-para-principiantes-20ag

Learn how to build and deploy a serverless AI chat application powered by Claude 3.5 Sonnet (Anthropic) on AWS Bedrock, using AWS CDK (Python) — from scratch.

Perfect for beginners exploring AWS, Infrastructure as Code, and generative AI development in the AWS ecosystem.


🎯 What You Will Build

In this hands-on project you will deploy:

  • A Lambda function that invokes Claude 3.5 on AWS Bedrock
  • A REST API built with API Gateway (/chat)
  • A static web chat interface hosted on S3
  • Fully automated provisioning using AWS CDK (Python)

This tutorial gives you a complete end-to-end AI application running in minutes.


✅ Prerequisites

Make sure you have:

  • AWS account with Bedrock model access enabled → Bedrock Console → Model Access → anthropic.claude-3-5-sonnet-20240620
  • Region: us-east-1
  • AWS CDK installed:
  npm install -g aws-cdk
Enter fullscreen mode Exit fullscreen mode
  • AWS credentials set using aws configure

📦 1. Clone the Project

git clone https://github.com/r3xakead0/aws-cdk-bedrock-claude.git
cd aws-cdk-bedrock-claude
Enter fullscreen mode Exit fullscreen mode

Activate a virtual environment:

uv venv && source .venv/bin/activate
Enter fullscreen mode Exit fullscreen mode

Install dependencies:

uv sync
Enter fullscreen mode Exit fullscreen mode

🧱 2. Architecture Overview

architecture description

Flow:

  1. User sends a chat message
  2. Lambda sends request to Claude (Bedrock Runtime)
  3. Claude generates a response
  4. API Gateway returns the answer to the browser

Technologies used:

  • AWS Lambda
  • Amazon API Gateway
  • Amazon S3 (static hosting)
  • AWS Bedrock Runtime
  • AWS CDK (Python)

💡 3. Key CDK Components

Lambda – calls Claude 3.5 Sonnet

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

resp = bedrock_rt.invoke_model(
    modelId="anthropic.claude-3-5-sonnet-20240620",
    body=json.dumps({
        "anthropic_version": "bedrock-2023-05-31",
        "messages": [{"role": "user", "content": [{"type": "text", "text": prompt}]}],
        "max_tokens": 512
    })
)
Enter fullscreen mode Exit fullscreen mode

CDK handles IAM, permissions, packaging, and deployment automatically.


🚀 4. Deploy the Full Stack

Bootstrap (first time only):

cdk bootstrap
Enter fullscreen mode Exit fullscreen mode

Deploy:

cdk deploy
Enter fullscreen mode Exit fullscreen mode

You will get:

ApiUrl = https://xxxx.execute-api.us-east-1.amazonaws.com/prod/chat
WebsiteUrl = http://claudechatdemo.s3-website-us-east-1.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

💬 5. How to Test Your Claude Chat App on AWS

Open the website and paste your ApiUrl.

http://claudechatdemo.s3-website-us-east-1.amazonaws.com/
Enter fullscreen mode Exit fullscreen mode

Try this message:

Do you know what a bucket is?
Enter fullscreen mode Exit fullscreen mode

chat web

Claude will respond immediately with the generated output.

Yes, I'm familiar with buckets in various contexts. The term "bucket" can have different meanings depending on the context
1. In everyday usage, a bucket is a container used for carrying or storing liquids or other materials
2. In computer science and cloud computing:
  - A bucket is a fundamental container for storing data in object storage services like Amazon S3 (Simple Storage Service).
  - It's used to organize and control access to data objects
3. In data structures, a bucket is a container that can hold multiple items, often used in hash tables or for sorting algorithms (e.g., bucket sort)
4. In statistics and data analysis, data can be grouped into "buckets" or ranges for easier analysis or visualization
5. In project management, "bucket" might refer to a category or group of related tasks or resources
Given that you're asking about buckets in the context of an AWS expert, I assume you're most likely referring to S3 buckets or similar cloud storage concepts. If you have a more specific question about buckets in a particular context, please feel free to ask.
Enter fullscreen mode Exit fullscreen mode

This is your fully serverless, pay-per-use AI chat app running on AWS ✨


🧪 6. Test Using curl

API="https://xxxx.execute-api.us-east-1.amazonaws.com/prod/chat"

curl -s -X POST "$API" \
  -H 'Content-Type: application/json' \
  -d '{"prompt":"Summarize AWS Bedrock in 3 bullets"}' | jq
Enter fullscreen mode Exit fullscreen mode

🧹 7. Clean Up

To avoid charges:

cdk destroy
Enter fullscreen mode Exit fullscreen mode

This removes Lambda, API Gateway, and S3.


🧭 What You Learned

  • How to deploy AI workloads with AWS Bedrock
  • How to build serverless architectures using AWS CDK
  • How to host frontend apps on Amazon S3
  • How to integrate Claude with your own applications

🌟 Conclusion

This guide shows how easy it is to combine serverless, IaC, and AI to create real, production-ready applications on AWS.

🔗 Source code (open-source): r3xakead0/aws-cdk-bedrock-claude

If this tutorial helped you, leave a ❤️ and tell me which Bedrock model you want to try next!

Top comments (0)