DEV Community

Cover image for How I Deployed CrewAI Multi-Agent Teams on Amazon Bedrock AgentCore Without Writing a Single Dockerfile

How I Deployed CrewAI Multi-Agent Teams on Amazon Bedrock AgentCore Without Writing a Single Dockerfile

How I Deployed CrewAI Multi-Agent Teams on Amazon Bedrock AgentCore Without Writing a Single Dockerfile

Building AI agents is exciting, but deploying them to production? That's where the real magic happens. Today we're diving deep into Amazon Bedrock AgentCore β€” AWS's serverless runtime for AI agents that eliminates all the infrastructure headaches.

the idea here is simple: you build your CrewAI multi-agent teams locally, test them thoroughly, and then deploy to AgentCore with the AgentCore CLI. No Dockerfiles, no scaling concerns, no operational overhead.

What makes this particularly interesting is how AgentCore bridges the gap between local development and production deployment. You write your agent code once, test it on localhost:8080, and then deploy it to a fully managed serverless environment available in 15 AWS regions.

πŸ““ Full working notebook: All the code in this post is validated and executable in the companion Jupyter notebook β€” including deploy and cleanup.

Here as well in my github link below: https://github.com/breakingthecloud/crewai-agentcore-deployment/blob/main/bedrock-agentcore-crewai-validation.ipynb

Why AgentCore Changes the Game

Traditional AI agent deployment involves containers, load balancers, auto-scaling groups, and a whole infrastructure stack. AgentCore flips this model:

  • Serverless by design: No servers to manage, automatic scaling
  • Session isolation: Each user interaction runs in isolated environments
  • Extended execution: Support for both real-time interactions and long-running workloads
  • Built-in observability: CloudWatch integration, traces, and logs out of the box
  • Framework agnostic: Works with CrewAI, LangGraph, Strands Agents, Google ADK, OpenAI Agents, and custom frameworks
  • Consumption-based pricing: Pay only for what you use

En la prΓ‘ctica esto significa that you focus on building intelligent agents while AWS handles all the operational complexity.

The Architecture

Here's what we're building: a CrewAI multi-agent system deployed on AgentCore Runtime using the AgentCore CLI with CodeZip deployment (no containers needed).

Local Development          β†’    AgentCore Runtime (AWS)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ crewai_agent.py  β”‚  agentcore β”‚ Serverless Runtime    β”‚
β”‚ @app.entrypoint  β”‚  deploy   β”‚ Session Isolation     β”‚
β”‚ localhost:8080   β”‚ ────────► β”‚ Auto-scaling          β”‚
β”‚ CrewAI + Bedrock β”‚           β”‚ CloudWatch Logs       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

Step 1: Setting Up the Environment

The AgentCore CLI is an npm package β€” not pip. This was one of the key things I learned (the old bedrock-agentcore-starter-toolkit pip package is deprecated).

# Install AgentCore CLI (requires Node.js 20+)
npm install -g @aws/agentcore

# Verify
agentcore --version

# Install Python SDK
pip install bedrock-agentcore crewai
Enter fullscreen mode Exit fullscreen mode

Step 2: The Agent Code β€” The @app.entrypoint Pattern

The core of AgentCore integration is the BedrockAgentCoreApp with the @app.entrypoint decorator. This is what makes your code work both locally and in the cloud.

One critical lesson learned: use lazy imports for CrewAI. CrewAI has heavy dependencies that take more than 30 seconds to import, which exceeds AgentCore's initialization timeout. Moving the imports inside the handler solves this.

from bedrock_agentcore.runtime import BedrockAgentCoreApp
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

app = BedrockAgentCoreApp()

@app.entrypoint
def crewai_handler(payload, context):
    """Main AgentCore entrypoint β€” lazy imports to avoid cold start timeout."""
    try:
        # Lazy imports: CrewAI is heavy, import inside handler
        from crewai import Agent, Crew, Process, Task, LLM
        from crewai.tools import BaseTool

        class KnowledgeSearchTool(BaseTool):
            name: str = "knowledge_search"
            description: str = "Search AWS documentation and technical knowledge"
            def _run(self, query: str) -> str:
                kb = {
                    "s3": "Object storage with 99.999999999% durability",
                    "lambda": "Serverless compute with automatic scaling",
                    "agentcore": "Secure serverless runtime for AI agents",
                }
                results = [f"{k.upper()}: {v}" for k, v in kb.items()
                          if any(w.lower() in v.lower() for w in query.split())]
                return "\n".join(results) or "No results found"

        user_input = payload.get("prompt", "How can I help you?")
        logger.info(f"Processing: {user_input}")

        llm = LLM(model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0", temperature=0.1)

        researcher = Agent(
            role="AWS Research Specialist",
            goal="Find comprehensive AWS service information",
            backstory="Expert researcher with deep AWS knowledge",
            tools=[KnowledgeSearchTool()],
            llm=llm, verbose=False,
        )

        crew = Crew(
            agents=[researcher],
            tasks=[Task(description=f"Research: {user_input}",
                       agent=researcher, expected_output="Research findings")],
            process=Process.sequential, verbose=False,
        )

        result = crew.kickoff()
        return {
            "result": result.raw,
            "status": "success",
            "session_id": context.session_id,
        }
    except Exception as e:
        logger.error(f"Error: {str(e)}")
        return {"result": f"Error: {str(e)}", "status": "error"}

if __name__ == "__main__":
    app.run()
Enter fullscreen mode Exit fullscreen mode

A few things to note about the model choice: I'm using us.anthropic.claude-haiku-4-5-20251001-v1:0 β€” an inference profile ID, not a raw model ID. Newer Anthropic models on Bedrock require inference profiles (prefixed with us. or global.). Also, CrewAI uses assistant message prefill internally, which some newer Claude models don't support β€” Haiku 4.5 works perfectly.

Step 3: Local Testing

When you run your agent file, AgentCore automatically starts a web server on localhost:8080. No Flask, no FastAPI β€” it's all handled for you.

# Start the agent locally
python crewai_agent.py

# Test in another terminal
curl -X POST http://localhost:8080/invocations \
  -H "Content-Type: application/json" \
  -d '{"prompt": "What is AWS Lambda?"}'
Enter fullscreen mode Exit fullscreen mode

Step 4: Deploy to AgentCore Runtime

This is where it gets real. The AgentCore CLI handles everything β€” project scaffolding, CDK infrastructure, and deployment.

# Create project (generates agentcore.json + CDK infrastructure)
agentcore create --name CrewAIAgent --defaults

# Copy your agent code into the project
cp crewai_agent.py CrewAIAgent/app/CrewAIAgent/main.py

# Configure deployment target (account + region)
# Edit CrewAIAgent/agentcore/aws-targets.json:
# [{"name": "default", "account": "YOUR_ACCOUNT_ID", "region": "us-east-1"}]

# Deploy (uses AWS CDK under the hood)
cd CrewAIAgent
agentcore deploy --yes
Enter fullscreen mode Exit fullscreen mode

The deploy process:

  1. Packages your code as a CodeZip archive
  2. Uses AWS CDK to synthesize and provision CloudFormation resources
  3. Creates IAM roles and AgentCore Runtime endpoint
  4. Configures CloudWatch logging and observability

Important: The AgentCore execution role needs Marketplace permissions for third-party models (Anthropic). After deploy, add this to the role:

iam.put_role_policy(
    RoleName=role_name,
    PolicyName='MarketplaceModelAccess',
    PolicyDocument=json.dumps({
        'Version': '2012-10-17',
        'Statement': [{
            'Effect': 'Allow',
            'Action': ['aws-marketplace:ViewSubscriptions',
                      'aws-marketplace:Subscribe',
                      'aws-marketplace:Unsubscribe'],
            'Resource': '*'
        }]
    })
)
Enter fullscreen mode Exit fullscreen mode

The notebook handles this automatically in the deploy cell.

Step 5: Invoke Your Deployed Agent

# Using AgentCore CLI
agentcore invoke --prompt "What is AWS Lambda? Answer in 3 sentences." --json

# Response:
# {
#   "response": "AWS Lambda is a serverless compute service that allows you to run
#    code without provisioning or managing servers, with automatic scaling capabilities
#    to handle varying workloads. Lambda executes code in response to events from
#    various AWS services and automatically scales your application by running code
#    only when needed. You pay only for the compute time you consume, making it a
#    cost-effective solution for event-driven applications and microservices architectures."
# }
Enter fullscreen mode Exit fullscreen mode

You can also invoke programmatically with boto3:

import boto3, json, uuid

client = boto3.client('bedrock-agentcore')
response = client.invoke_agent_runtime(
    agentRuntimeArn="arn:aws:bedrock-agentcore:us-east-1:123456789012:runtime/your-runtime-id",
    runtimeSessionId=str(uuid.uuid4()),  # Required parameter
    payload=json.dumps({"prompt": "What is AWS Lambda?"}).encode(),
    qualifier="DEFAULT"
)
Enter fullscreen mode Exit fullscreen mode

Step 6: Cleanup

agentcore remove all --yes
agentcore deploy --yes  # Deploys empty state to tear down resources
Enter fullscreen mode Exit fullscreen mode

Lessons Learned

Building this end-to-end, I hit several gotchas that aren't obvious from the docs:

Issue Solution
Old Starter Toolkit Use npm install -g @aws/agentcore, not pip install bedrock-agentcore-starter-toolkit
Init timeout (30s) Lazy imports β€” move import crewai inside the handler
Model prefill error Use Claude Haiku 4.5 (supports assistant prefill that CrewAI needs)
Inference profiles Use us.anthropic.claude-* prefix, not raw model IDs
Marketplace permissions Add aws-marketplace:ViewSubscriptions and Subscribe to execution role
aws-targets.json Field is account (not accountId)
AWS credentials for CLI Export SSO credentials to env vars before running agentcore deploy

Key Takeaways

Lo interesante es que AgentCore eliminates the traditional deployment complexity for AI agents:

  • The AgentCore CLI (@aws/agentcore) is the current tool β€” it uses AWS CDK, not CodeBuild/ECR
  • CodeZip deployment means no Dockerfiles β€” just your Python code in a zip
  • @app.entrypoint is the only decorator you need to go from local to cloud
  • Lazy imports are essential for heavy frameworks like CrewAI
  • 15 regions available for AgentCore Runtime
  • Consumption-based pricing β€” you pay only for actual compute time

Mi recomendaciΓ³n: start with the notebook, run it end-to-end, and then adapt the agent code for your use case. The deployment flow is surprisingly smooth once you know the gotchas.


Connect with me:

I'm Carlos Cortez, this is Breaking the Cloud, and remember β€” the best way to learn is by building. See you in the next one!

Top comments (0)