Introduction
Managing AWS infrastructure can be overwhelming, especially when you're juggling multiple services, trying to optimize costs, and ensuring security best practices. What if you had an AI assistant that could help you with these daily AWS tasks? In this blog post, I'll walk you through how I built an intelligent AWS helper using the Strands Agents framework and deployed it to AWS Bedrock AgentCore.
Why Build This?
As someone who works with AWS regularly, I found myself repeatedly searching for the same information:
- "What's the best EC2 instance type for my workload?"
- "How do I secure my S3 buckets properly?"
- "Why is my Lambda function timing out?"
- "How can I reduce my AWS bill?"
Instead of constantly searching documentation or asking colleagues, I decided to build an AI assistant that could provide instant, expert guidance on these common AWS questions.
The Tech Stack
Strands Agents Framework
Strands Agents is a powerful framework for building AI agents. It provides:
- Clean abstractions for agent logic
- Built-in deployment capabilities
- Integration with major cloud platforms
- Chain of thought reasoning support
AWS Bedrock AgentCore
AWS Bedrock AgentCore is Amazon's managed service for deploying and running AI agents. It offers:
- Serverless architecture
- Automatic scaling
- Integration with other AWS services
- Built-in monitoring and logging
Architecture Overview
Before diving into the code, let's understand how the system works:
User Query → Bedrock Runtime → Handler → Agent → Service Handler → Response
The architecture consists of several layers:
- User Interface Layer: AWS Console, CLI, or API
- Bedrock Runtime: Managed service that hosts the agent
- Handler Layer: Routes requests to the agent
- Agent Logic: Analyzes queries and routes to service handlers
- Service Handlers: Specialized handlers for EC2, S3, Lambda, Cost, etc.
Here's a visual representation:
┌─────────────────────────────────────────────────────────┐
│ User Interface │
│ (Console / CLI / API / SDK) │
└────────────────────┬────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ AWS Bedrock AgentCore │
│ ┌────────────────────────────────────────────┐ │
│ │ Agent Runtime & Router │ │
│ └──────────────────┬─────────────────────────┘ │
└─────────────────────┼───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ @app.handler Function │
│ • Extracts user input from event │
│ • Calls agent.process_request() │
│ • Formats and returns response │
└──────────────────────┬──────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ AWSHelpingAssistant Agent │
│ ┌────────────────────────────────────────┐ │
│ │ Keyword Analysis & Routing │ │
│ └───┬────────┬────────┬────────┬────────┘ │
│ │ │ │ │ │
│ ┌──▼──┐ ┌──▼──┐ ┌───▼───┐ ┌──▼──┐ │
│ │ EC2 │ │ S3 │ │Lambda │ │Cost │ │
│ └─────┘ └─────┘ └───────┘ └─────┘ │
└─────────────────────────────────────────────────────────┘
This serverless architecture automatically scales based on demand and requires zero infrastructure management.
Building the Agent
Step 1: Defining the Agent Class
I started by creating an AWSHelpingAssistant class that extends the Strands Agent base class:
from strands import Agent
from bedrock_agentcore.runtime import BedrockAgentCoreApp
app = BedrockAgentCoreApp()
class AWSHelpingAssistant(Agent):
def __init__(self):
super().__init__(
name="AWS Daily Helper",
description="An AI assistant that helps with daily AWS tasks",
instructions="""You are an AWS expert assistant..."""
)
The agent includes clear instructions that define its capabilities and behavior, ensuring consistent and helpful responses.
Step 2: Implementing Query Handlers
I organized the agent's functionality into specialized handlers for different AWS services:
- EC2 Handler: Provides guidance on instance optimization, security groups, and Auto Scaling
- S3 Handler: Offers best practices for storage classes, versioning, and security
- Lambda Handler: Helps with function optimization and troubleshooting
- Cost Handler: Assists with billing analysis and cost reduction strategies
- General Handler: Provides overall AWS guidance and recommendations
Each handler returns actionable advice tailored to the specific AWS service.
Step 3: Creating the Bedrock Handler
The key to deploying on Bedrock AgentCore is implementing the handler function:
@app.handler
async def handler(event, context):
user_input = event.get("inputText", "")
response = await agent.process_request(user_input)
return {
"response": response,
"sessionAttributes": event.get("sessionAttributes", {}),
}
This handler receives events from Bedrock, processes them through the agent, and returns formatted responses.
Deployment Process
Setting Up Dependencies
First, I created a requirements.txt file with the necessary dependencies:
strands-agents
bedrock-agentcore
boto3
bedrock-agentcore-starter-toolkit
Install them with:
pip install -r requirements.txt
Local Testing First
Before deploying to AWS, I tested the agent locally:
python my-agent.py
This runs a series of test queries to ensure everything works correctly.
For a more production-like test, you can use the AgentCore toolkit with Docker:
agentcore launch --local
Deploying to Bedrock with Starter Toolkit
Deployment is incredibly straightforward with the AgentCore Starter Toolkit:
Step 1: Configure the agent
agentcore configure --entrypoint my-agent.py
This command will:
- Set up the necessary configuration for deployment
- Create a Dockerfile for containerization
- Prepare your agent for AWS deployment
Step 2: Deploy to AWS
agentcore launch
That's it! The toolkit handles:
- Packaging the agent code
- Creating necessary AWS resources
- Configuring IAM permissions
- Setting up the Bedrock agent
- Providing the agent endpoint
Step 3: Test the deployed agent
agentcore invoke '{"prompt": "How can I optimize my EC2 costs?"}'
Run the command python chat.py for interactive session
Step 4: Dont Forgot to Destroy
agentcore destroy
Real-World Usage
Once deployed, the agent can be accessed through:
- AWS Console: Test directly in the Bedrock interface
- API Calls: Integrate into applications using boto3
- AWS SDK: Use from any AWS-supported programming language
Example Interaction
User: "How can I optimize my EC2 costs?"
Agent:
**EC2 Assistance**
Here's help with your EC2 question:
- Check your instance types and sizes for cost optimization
- Ensure security groups are properly configured
- Consider using Auto Scaling for better resource management
- Monitor CloudWatch metrics for performance insights
Would you like specific guidance on any of these areas?
Benefits of This Approach
1. Always Available
The agent runs 24/7 on AWS infrastructure, ready to help whenever needed.
2. Consistent Advice
Unlike searching through documentation, the agent provides consistent, structured guidance based on AWS best practices.
3. Scalable
Bedrock AgentCore automatically scales to handle multiple concurrent users without any infrastructure management.
4. Cost-Effective
You only pay for what you use, with no servers to maintain or manage.
5. Easy to Extend
Adding new capabilities is as simple as implementing new handler methods.
Conclusion
Building an AI agent with Strands and deploying it to AWS Bedrock AgentCore was surprisingly straightforward. The combination of Strands' clean abstractions and Bedrock's managed infrastructure made it possible to go from idea to production in a matter of hours.
If you're working with AWS regularly, I highly recommend building your own helper agent. It's a great way to:
- Learn about AI agent development
- Improve your AWS knowledge
- Create a useful tool for your team
- Explore the capabilities of modern AI frameworks
Get Started
The complete code is available on GitHub. Clone it, customize it for your needs, and deploy your own AWS helper agent today!
Resources
Questions?
Feel free to reach out if you have questions about building AI agents or deploying to AWS Bedrock. I'd love to hear about your experiences and what you build!
Happy building! 🚀










Top comments (0)