DEV Community

Cover image for Bring AI agents into production in minutes
Elizabeth Fuentes L for AWS

Posted on • Originally published at builder.aws.com

Bring AI agents into production in minutes

πŸ‡»πŸ‡ͺπŸ‡¨πŸ‡± Dev.to Linkedin GitHub Twitter Instagram Youtube
Linktr

🀯 The Production Deployment Problem Every Developer Faces

You've built an incredible AI agent. It works well on your laptop.

Now you need to deploy it to production.

Here's what usually happens:

  • 3 weeks setting up infrastructure ⏰
  • Docker and Kubernetes nightmares 🐳
  • Security configurations that make you cry πŸ”
  • Scaling policies you barely understand πŸ“ˆ
  • Session management... what even is that? 🀷

Sound familiar?

Amazon Bedrock AgentCore changes everything.

Deploy production-ready AI agents with just 2 commands. No DevOps degree required. No infrastructure headaches.

This hands-on tutorial shows you exactly how - from local testing to production endpoint in under 15 minutes.

This tutorial is based on Mike Chambers' blog: Turn Your AI Script into a Production-Ready Agent, Thanks Mike :)

🎯 What You'll Build

  • βœ… A calculator AI agent with Strands Agents and Claude as the model provider
  • βœ… Secure APIKey management with AgentCore Identity
  • βœ… Auto-scaling production deployment
  • βœ… Session-aware conversations
  • βœ… Full monitoring and observability

AgentCore Services Overview

Service Purpose Key Features
⭐ AgentCore Runtime Serverless execution Auto-scaling, Session management, Container orchestration
⭐ AgentCore Identity Credential management API keys, OAuth tokens, Secure vault
AgentCore Memory State persistence Short-term memory, Long-term storage
AgentCore Code Interpreter Code execution Secure sandbox, Data analysis
AgentCore Browser Web interaction Cloud browser, Auto-scaling
AgentCore Gateway API management Tool discovery, Service integration
AgentCore Observability Monitoring Tracing, Dashboards, Debugging

⭐ Used in this tutorial: Runtime and Identity services handle deployment and credential management.

Prerequisites

Before you begin, verify that you have:

New AWS customers receive up to $200 in credits

Start at no cost with AWS Free Tier. Get $100 USD at sign-up plus $100 USD more exploring key services.

Let's turn your prototype into production. πŸš€

Tutorial Roadmap:

  1. Setup βš™οΈ β†’ 2. Code Agent πŸ’» β†’ 3. Test Locally βœ… β†’ 4. Deploy πŸš€ β†’ 5. Invoke ⚑

Estimated time: 15 minutes

Create IAM User

Create an AWS IAM user and attach the BedrockAgentCoreFullAccess managed policy.

Configure AgentCore Identity

Create credential providers through the AgentCore console Identity menu. Store your Claude API key securely using AgentCore Identity's encrypted vault.

AgentCore Identity provides comprehensive credential management with secure storage, OAuth support, and access control across multiple authentication systems.

Install Dependencies

python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Required packages:

  • bedrock-agentcore - AgentCore SDK
  • strands-agents - Agent framework
  • bedrock-agentcore-starter-toolkit - Deployment toolkit
  • strands-agents-tools - Calculator functionality

Agent Implementation

AgentCore Entry Point

The @app.entrypoint decorator makes your agent deployable:

@app.entrypoint
def invoke(payload, context):
    """AgentCore Runtime entry point"""
    agent = create_agent(calculator)

    prompt = payload.get("prompt", "Hello!")
    result = agent(prompt)

    return {
        "response": result.message.get('content', [{}])[0].get('text', str(result))
    }
Enter fullscreen mode Exit fullscreen mode

Secure Credential Management

@requires_api_key(provider_name="ClaudeAPIKeys")
async def retrieve_api_key(*, api_key: str):
    os.environ["CLAUDE_APIKEY"] = api_key
Enter fullscreen mode Exit fullscreen mode

AgentCore Identity retrieves API keys securely without exposing credentials in your code.

Model Configuration

def create_model():
    return AnthropicModel(
        client_args={"api_key": os.environ["CLAUDE_APIKEY"]},
        max_tokens=4000,
        model_id="claude-3-5-haiku-20241022",
        params={"temperature": 0.3}
    )
Enter fullscreen mode Exit fullscreen mode

Performance Optimization

Initialize agents once per session to preserve state and reduce latency:

agent = None
def create_agent(tools):
    global agent
    if agent is None:
        agent = Agent(
            model=create_model(),
            tools=[tools],
            system_prompt="You are a helpful assistant that can perform calculations. Use the calculate tool for any math problems."
        )
    return agent
Enter fullscreen mode Exit fullscreen mode

AgentCore provides session isolation in dedicated containers that run up to 8 hours.

Test Locally

Start your agent:

python3 my_agent.py
Enter fullscreen mode Exit fullscreen mode

Test functionality:

curl -X POST http://localhost:8080/invocations \
  -H "Content-Type: application/json" \
  -d '{"prompt": "What is 50 plus 30?"}'
Enter fullscreen mode Exit fullscreen mode

Deploy to Production

Deploy with two commands:

Configure Agent

agentcore configure -e my_agent.py
Enter fullscreen mode Exit fullscreen mode

Provide your IAM role ARN when prompted.

Launch to Production

agentcore launch
Enter fullscreen mode Exit fullscreen mode

AgentCore automatically:

  • Creates runtime environment
  • Sets up auto-scaling
  • Configures security
  • Provides production endpoint

Verify Deployment

agentcore status
Enter fullscreen mode Exit fullscreen mode

View agent status, endpoint information, and observability dashboards.

You can also monitor deployment progress in the AgentCore console:

Invoke Your Agent

Terminal Testing

agentcore invoke '{"prompt": "What is 50 plus 30?"}' --session-id session-123 --user-id user-456
Enter fullscreen mode Exit fullscreen mode
agentcore invoke '{"prompt": "Now multiply that result by 2"}' --session-id session-123 --user-id user-456
Enter fullscreen mode Exit fullscreen mode

Production Integration

Use AWS SDK for application integration:

import boto3
import json

client = boto3.client('bedrock-agentcore-runtime', region_name='us-west-2')
agent_arn = "arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/your-agent-name"

response = client.invoke_agent_runtime(
    agentRuntimeArn=agent_arn,
    sessionId="production_session_2024_user456",
    inputText="What is 25 * 4 + 10?"
)

result = json.loads(response['body'].read())
print(result['response'])
Enter fullscreen mode Exit fullscreen mode

Production Requirements:

  • Get Agent ARN from agentcore status
  • Session IDs must be 33+ characters
  • Uses AWS credentials for authentication
  • Supports streaming responses

Why AgentCore vs Traditional Deployment?

Traditional Deployment AgentCore Deployment
❌ 3 weeks βœ… 15 minutes
❌ Docker + K8s βœ… Serverless
❌ Manual scaling βœ… Auto-scaling
❌ Complex security βœ… Built-in security
❌ DevOps expertise βœ… 2 commands

Clean Up

Remove all resources:

agentcore destroy
Enter fullscreen mode Exit fullscreen mode

This removes AgentCore deployment, ECR repository, IAM roles, and CloudWatch logs.

πŸŽ‰ You Just Deployed Your First Production AI Agent!

Now comes the fun part: What will you build? πŸš€

πŸ’‘ Taking It Further

I've been building various AI agents with Strands Agents - from multimodal content processing to multi-agent systems. Now I'm taking them all to production with AgentCore.

If you're curious about what's possible, check out some of the agents I've built:

🎨 Multimodal AI Agents

Process images, videos, and text together:

🀝 Multi-Agent Systems

Agents working together:

🧠 RAG and Memory

Make agents remember and learn:

Next up: I'll be showing how to deploy these advanced agents to production with AgentCore.


❀️ If This Helped You

  • ❀️ Heart it - helps others discover this tutorial
  • πŸ¦„ Unicorn it - if it blew your mind
  • πŸ”– Bookmark it - for when you need it later
  • πŸ“€ Share it - with your team or on social media

πŸ“š Resources

AgentCore:

AWS Free Tier:

My Other Tutorials:


Happy building! πŸš€

πŸ‡»πŸ‡ͺπŸ‡¨πŸ‡± Dev.to Linkedin GitHub Twitter Instagram Youtube
Linktr

Top comments (1)

Collapse
 
ensamblador profile image
ensamblador • Edited

Excellent, this is great!