Course Overview All Courses Blog Reserve Bootcamp Seat
AWS for AI · Day 5 of 5 ~90 minutes

Deploy an AI App on AWS — App Runner

Write a FastAPI app, containerize it with Docker, push to ECR, deploy on App Runner. Live URL. Real production app.

Day 1
Day 2
Day 3
Day 4
5
Day 5
What You'll Build Today

A deployed AI API: a FastAPI endpoint that accepts a text prompt, calls Claude via Bedrock, and returns the response as JSON. Containerized with Docker, image stored in ECR, running on App Runner with a public HTTPS URL.

1
The App

Build the FastAPI app

Install dependencies:

bash
pip install fastapi uvicorn boto3

Create main.py:

pythonmain.py
from fastapi import FastAPI
from pydantic import BaseModel
import boto3, json

app = FastAPI(title="AI API")
bedrock = boto3.client("bedrock-runtime", region_name="us-east-1")

class Prompt(BaseModel):
    text: str
    max_tokens: int = 512

@app.get("/")
def root():
    return {"status": "healthy", "service": "AI API"}

@app.post("/generate")
def generate(prompt: Prompt):
    resp = bedrock.invoke_model(
        modelId="anthropic.claude-opus-4-5-20251101-v1:0",
        body=json.dumps({
            "anthropic_version": "bedrock-2023-05-31",
            "max_tokens": prompt.max_tokens,
            "messages": [{"role": "user", "content": prompt.text}]
        }),
        contentType="application/json", accept="application/json"
    )
    result = json.loads(resp["body"].read())
    return {"response": result["content"][0]["text"]}
2
Docker + ECR

Containerize and push to ECR

Create a Dockerfile:

dockerfileDockerfile
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY main.py .
EXPOSE 8080
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]

Create requirements.txt with: fastapi uvicorn boto3 pydantic

Push to ECR:

bash
# Create ECR repo
aws ecr create-repository --repository-name ai-api --region us-east-1

# Login to ECR (replace ACCOUNT_ID)
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com

# Build, tag, push
docker build -t ai-api .
docker tag ai-api:latest ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/ai-api:latest
docker push ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/ai-api:latest
3
App Runner

Deploy with App Runner

In the console: App Runner → Create service. Source: Container registry → Amazon ECR. Select your ai-api image. Port: 8080.

For the instance role, create a new role with AmazonBedrockFullAccess.

Click Deploy. Wait 3-5 minutes. App Runner gives you a URL like https://abc123.us-east-1.awsapprunner.com.

Test it:

bash
curl -X POST https://YOUR-URL.awsapprunner.com/generate \
  -H "Content-Type: application/json" \
  -d '{"text": "Explain AWS App Runner in one sentence."}'

You just deployed a production AI app. It auto-scales, has HTTPS, handles load balancing, and runs on AWS infrastructure. Delete the service when done to avoid charges (~$0.064/vCPU-hour).

Day 5 Complete — Course Complete

  • Built a FastAPI app that calls Bedrock Claude
  • Containerized with Docker and pushed to Amazon ECR
  • Deployed on App Runner with a live HTTPS URL
  • Completed the full AWS AI stack: IAM → Bedrock → Lambda → Knowledge Bases → App Runner
Course Complete

You built the full AWS AI stack.

In 5 days you went from zero AWS to a deployed production AI application. Most developers never get this far. You just did it in a week.

Finished this lesson?