Skip to content

Commit 6035777

Browse files
committed
Restructure infrastructure samples: rename to 04-infrastructure-as-code and organize CloudFormation templates
- Rename 04-cfn-samples to 04-infrastructure-as-code - Create cloudformation subfolder for better organization - Rename weather-agent-runtime to end-to-end-weather-agent - Rename weather agent template.yaml to end-to-end-weather-agent.yaml - Update all documentation and scripts to reflect new structure - Update main README with new paths and folder structure - All Python files pass ruff formatting checks
1 parent 359994b commit 6035777

File tree

24 files changed

+93
-103
lines changed

24 files changed

+93
-103
lines changed

04-cfn-samples/README.md renamed to 04-infrastructure-as-code/README.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ These CloudFormation templates enable you to:
1212

1313
## 📚 Available Samples
1414

15-
### 01. [Hosting MCP Server on AgentCore Runtime](./mcp-server-agentcore-runtime/)
15+
### 01. [Hosting MCP Server on AgentCore Runtime](./cloudformation/mcp-server-agentcore-runtime/)
1616

1717
Deploy a complete MCP (Model Context Protocol) server with automated Docker image building and JWT authentication.
1818

@@ -34,14 +34,14 @@ Deploy a complete MCP (Model Context Protocol) server with automated Docker imag
3434

3535
**Quick start:**
3636
```bash
37-
cd mcp-server-agentcore-runtime
37+
cd cloudformation/mcp-server-agentcore-runtime
3838
./deploy.sh
3939
./test.sh
4040
```
4141

4242
---
4343

44-
### 02. [Basic Agent Runtime](./basic-runtime/)
44+
### 02. [Basic Agent Runtime](./cloudformation/basic-runtime/)
4545

4646
Deploy a basic AgentCore Runtime with a simple Strands agent - no additional tools or memory.
4747

@@ -61,14 +61,14 @@ Deploy a basic AgentCore Runtime with a simple Strands agent - no additional too
6161
```bash
6262
aws cloudformation create-stack \
6363
--stack-name basic-agent-demo \
64-
--template-body file://basic-runtime/template.yaml \
64+
--template-body file://cloudformation/basic-runtime/template.yaml \
6565
--capabilities CAPABILITY_IAM \
6666
--region us-east-1
6767
```
6868

6969
---
7070

71-
### 03. [Multi-Agent Runtime](./multi-agent-runtime/)
71+
### 03. [Multi-Agent Runtime](./cloudformation/multi-agent-runtime/)
7272

7373
Deploy a multi-agent system where Agent1 (orchestrator) can invoke Agent2 (specialist) for complex tasks.
7474

@@ -90,14 +90,14 @@ Deploy a multi-agent system where Agent1 (orchestrator) can invoke Agent2 (speci
9090
```bash
9191
aws cloudformation create-stack \
9292
--stack-name multi-agent-demo \
93-
--template-body file://multi-agent-runtime/template.yaml \
93+
--template-body file://cloudformation/multi-agent-runtime/template.yaml \
9494
--capabilities CAPABILITY_IAM \
9595
--region us-east-1
9696
```
9797

9898
---
9999

100-
### 04. [Weather Agent with Tools and Memory](./weather-agent-runtime/)
100+
### 04. [End-to-End Weather Agent with Tools and Memory](./cloudformation/end-to-end-weather-agent/)
101101

102102
Deploy a complete weather-based activity planning agent with browser automation, code interpreter, and memory.
103103

@@ -126,7 +126,7 @@ Deploy a complete weather-based activity planning agent with browser automation,
126126
```bash
127127
aws cloudformation create-stack \
128128
--stack-name weather-agent-demo \
129-
--template-body file://weather-agent-runtime/template.yaml \
129+
--template-body file://cloudformation/end-to-end-weather-agent/end-to-end-weather-agent.yaml \
130130
--capabilities CAPABILITY_IAM \
131131
--region us-west-2
132132
```
@@ -182,23 +182,24 @@ Default values:
182182
## Repository Structure
183183

184184
```
185-
04-cfn-samples/
186-
├── README.md # This file
187-
├── mcp-server-agentcore-runtime/ # MCP Server sample
188-
│ ├── deploy.sh # Deployment script
189-
│ ├── test.sh # Testing script
190-
│ ├── cleanup.sh # Cleanup script
191-
│ ├── mcp-server-template.yaml # CloudFormation template
192-
│ ├── get_token.py # Authentication helper
193-
│ ├── test_mcp_server.py # MCP client test
194-
│ ├── README.md # Sample documentation
195-
│ └── DETAILED_GUIDE.md # Technical deep-dive
196-
├── basic-runtime/ # Basic agent sample
197-
│ └── template.yaml # CloudFormation template
198-
├── multi-agent-runtime/ # Multi-agent sample
199-
│ └── template.yaml # CloudFormation template
200-
└── weather-agent-runtime/ # Weather agent sample
201-
└── template.yaml # CloudFormation template
185+
04-infrastructure-as-code/
186+
├── README.md # This file
187+
└── cloudformation/ # CloudFormation samples
188+
├── mcp-server-agentcore-runtime/ # MCP Server sample
189+
│ ├── deploy.sh # Deployment script
190+
│ ├── test.sh # Testing script
191+
│ ├── cleanup.sh # Cleanup script
192+
│ ├── mcp-server-template.yaml # CloudFormation template
193+
│ ├── get_token.py # Authentication helper
194+
│ ├── test_mcp_server.py # MCP client test
195+
│ ├── README.md # Sample documentation
196+
│ └── DETAILED_GUIDE.md # Technical deep-dive
197+
├── basic-runtime/ # Basic agent sample
198+
│ └── template.yaml # CloudFormation template
199+
├── multi-agent-runtime/ # Multi-agent sample
200+
│ └── template.yaml # CloudFormation template
201+
└── end-to-end-weather-agent/ # Weather agent sample
202+
└── end-to-end-weather-agent.yaml # CloudFormation template
202203
```
203204

204205

@@ -242,5 +243,3 @@ aws service-quotas list-service-quotas \
242243
- [CloudFormation Best Practices](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html)
243244
- [CloudFormation Template Reference](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/AWS_BedrockAgentCore.html)
244245
- [Original Tutorials](../01-tutorials/)
245-
246-
File renamed without changes.

04-cfn-samples/weather-agent-runtime/README.md renamed to 04-infrastructure-as-code/cloudformation/end-to-end-weather-agent/README.md

Lines changed: 63 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Weather-Based Activity Planning Agent
2-
ded in this repository are for experimental and educational purposes only. They demonstrate concepts and techniques but are not intended for direct use in production environments.
1+
# End-to-End Weather Agent with Tools and Memory
32

43
This CloudFormation template deploys a complete, production-ready Amazon Bedrock AgentCore Runtime with a sophisticated weather-based activity planning agent. This demonstrates the full power of AgentCore by integrating Browser tool, Code Interpreter, Memory, and S3 storage in a single deployment.
54

@@ -52,62 +51,30 @@ The Weather Activity Planner agent can:
5251

5352
## Architecture
5453

55-
```
56-
┌──────────────────────────────────────────────────────────────────────┐
57-
│ CloudFormation Stack │
58-
│ │
59-
│ ┌─────────────────────────────────────────────────────────────────┐ │
60-
│ │ AgentCore Runtime │ │
61-
│ │ ┌───────────────────────────────────────────────────────────┐ │ │
62-
│ │ │ Weather Activity Planner Agent │ │ │
63-
│ │ │ │ │ │
64-
│ │ │ Workflow: │ │ │
65-
│ │ │ 1. Extract city from query │ │ │
66-
│ │ │ 2. Scrape weather data (Browser Tool) ──────────┐ │ │ │
67-
│ │ │ 3. Generate analysis code (LLM) │ │ │ │
68-
│ │ │ 4. Execute code (Code Interpreter) ─────────┐ │ │ │ │
69-
│ │ │ 5. Get preferences (Memory) ────────────┐ │ │ │ │ │
70-
│ │ │ 6. Generate recommendations │ │ │ │ │ │
71-
│ │ │ 7. Store in S3 (use_aws tool) ──────┐ │ │ │ │ │ │
72-
│ │ └──────────────────────────────────────│───│───│───│───────┘ │ │
73-
│ └───────────────────────────────────────────│───│───│───│─────────┘ │
74-
│ │ │ │ │ │
75-
│ ┌────────────────────────────────────────────│───│───│───│─────────┐ │
76-
│ │ Browser Tool │ │ │ │ │ │
77-
│ │ - WebSocket connection │ │ │ │ │ │
78-
│ │ - Puppeteer automation │ │ │ │ │ │
79-
│ │ - Weather.gov scraping │ │ │ │ │ │
80-
│ └────────────────────────────────────────────┘ │ │ │ │ │
81-
│ │ │ │ │
82-
│ ┌─────────────────────────────────────────────────│───│───│────────┐ │
83-
│ │ Code Interpreter Tool │ │ │ │ │
84-
│ │ - Weather classification logic │ │ │ │ │
85-
│ │ - Data analysis │ │ │ │ │
86-
│ └────────────────────────────────────────────────┘ │ │ │ │
87-
│ │ │ │
88-
│ ┌──────────────────────────────────────────────────────│───│───────┐ │
89-
│ │ Memory │ │ │ │
90-
│ │ - Activity preferences by weather type │ │ │ │
91-
│ │ - User session data │ │ │ │
92-
│ │ - 30-day retention │ │ │ │
93-
│ └────────────────────────────────────────────────────┘ │ │ │
94-
│ │ │
95-
│ ┌──────────────────────────────────────────────────────────│──────┐ │
96-
│ │ S3 Bucket (Results Storage) │ │ │
97-
│ │ - Markdown activity recommendations │ │ │
98-
│ │ - Versioning enabled │ │ │
99-
│ │ - Private access only │ │ │
100-
│ └─────────────────────────────────────────────────────────┘ │ │
101-
│ │
102-
│ ┌─────────────────────────────────────────────────────────────────┐ │
103-
│ │ Supporting Infrastructure │ │
104-
│ │ - ECR Repository (ARM64 container image) │ │
105-
│ │ - CodeBuild (automated image building) │ │
106-
│ │ - Lambda (custom resources & memory initialization) │ │
107-
│ │ - IAM Roles (comprehensive permissions) │ │
108-
│ └─────────────────────────────────────────────────────────────────┘ │
109-
└──────────────────────────────────────────────────────────────────────┘
110-
```
54+
![End-to-End Weather Agent Architecture](architecture.png)
55+
56+
The architecture demonstrates a complete AgentCore deployment with multiple integrated tools:
57+
58+
**Core Components:**
59+
- **User**: Sends weather-based activity planning queries
60+
- **AWS CodeBuild**: Builds the ARM64 Docker container image with the agent code
61+
- **Amazon ECR Repository**: Stores the container image
62+
- **AgentCore Runtime**: Hosts the Weather Activity Planner Agent
63+
- **Weather Agent**: Strands agent that orchestrates multiple tools
64+
- Invokes Amazon Bedrock LLMs for reasoning and code generation
65+
- **Browser Tool**: Web automation for scraping weather data from weather.gov
66+
- **Code Interpreter Tool**: Executes Python code for weather analysis
67+
- **Memory**: Stores user activity preferences (30-day retention)
68+
- **S3 Bucket**: Stores generated activity recommendations
69+
- **IAM Roles**: Comprehensive permissions for all components
70+
71+
**Workflow:**
72+
1. User sends query: "What should I do this weekend in Richmond VA?"
73+
2. Agent extracts city and uses Browser Tool to scrape 8-day forecast
74+
3. Agent generates Python code and uses Code Interpreter to classify weather
75+
4. Agent retrieves user preferences from Memory
76+
5. Agent generates personalized recommendations
77+
6. Agent stores results in S3 bucket using use_aws tool
11178

11279
## Prerequisites
11380

@@ -127,9 +94,6 @@ The Weather Activity Planner agent can:
12794

12895
3. **Bedrock Model Access**: Enable access to Amazon Bedrock models in your AWS region
12996
- Navigate to [Amazon Bedrock Console](https://console.aws.amazon.com/bedrock/)
130-
- Go to "Model access" and request access to:
131-
- Anthropic Claude 3.7 Sonnet (for browser automation)
132-
- Anthropic Claude 3.5 Sonnet or Haiku (for agent reasoning)
13397
- [Bedrock Model Access Guide](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html)
13498

13599
4. **Required Permissions**: Your AWS user/role needs permissions for:
@@ -164,7 +128,7 @@ The script will:
164128
# Deploy the stack
165129
aws cloudformation create-stack \
166130
--stack-name weather-agent-demo \
167-
--template-body file://template.yaml \
131+
--template-body file://end-to-end-weather-agent.yaml \
168132
--capabilities CAPABILITY_NAMED_IAM \
169133
--region us-west-2
170134

@@ -184,7 +148,7 @@ aws cloudformation describe-stacks \
184148

185149
1. Navigate to [CloudFormation Console](https://console.aws.amazon.com/cloudformation/)
186150
2. Click "Create stack" → "With new resources"
187-
3. Upload the `template.yaml` file
151+
3. Upload the `end-to-end-weather-agent.yaml` file
188152
4. Enter stack name: `weather-agent-demo`
189153
5. Review parameters (or use defaults)
190154
6. Check "I acknowledge that AWS CloudFormation might create IAM resources"
@@ -344,10 +308,12 @@ chmod +x cleanup.sh
344308
./cleanup.sh
345309
```
346310

311+
**Note**: If cleanup fails due to active browser sessions, see the AWS CLI cleanup method below for manual session termination.
312+
347313
### Using AWS CLI
348314

349315
```bash
350-
# Empty the S3 bucket first (required before deletion)
316+
# Step 1: Empty the S3 bucket (required before deletion)
351317
BUCKET_NAME=$(aws cloudformation describe-stacks \
352318
--stack-name weather-agent-demo \
353319
--region us-west-2 \
@@ -356,7 +322,27 @@ BUCKET_NAME=$(aws cloudformation describe-stacks \
356322

357323
aws s3 rm s3://$BUCKET_NAME --recursive
358324

359-
# Delete the stack
325+
# Step 2: Terminate any active browser sessions
326+
# Get the Browser ID
327+
BROWSER_ID=$(aws cloudformation describe-stacks \
328+
--stack-name weather-agent-demo \
329+
--region us-west-2 \
330+
--query 'Stacks[0].Outputs[?OutputKey==`BrowserId`].OutputValue' \
331+
--output text)
332+
333+
# List active sessions
334+
aws bedrock-agentcore list-browser-sessions \
335+
--browser-id $BROWSER_ID \
336+
--region us-west-2
337+
338+
# Terminate each active session (replace SESSION_ID with actual session ID from list command)
339+
# Repeat this command for each active session
340+
aws bedrock-agentcore terminate-browser-session \
341+
--browser-id $BROWSER_ID \
342+
--session-id SESSION_ID \
343+
--region us-west-2
344+
345+
# Step 3: Delete the stack
360346
aws cloudformation delete-stack \
361347
--stack-name weather-agent-demo \
362348
--region us-west-2
@@ -367,14 +353,19 @@ aws cloudformation wait stack-delete-complete \
367353
--region us-west-2
368354
```
369355

356+
**Important**: Browser sessions are automatically created when the agent uses the browser tool. Always terminate active sessions before deleting the stack to avoid deletion failures.
357+
370358
### Using AWS Console
371359

372360
1. Navigate to [S3 Console](https://console.aws.amazon.com/s3/)
373-
2. Find the bucket (name starts with `weather-agent-demo-agentcore-cfn-results`)
361+
2. Find the bucket (name format: `<stack-name>-results-<account-id>`, e.g., `weather-agent-demo-results-123456789012`)
374362
3. Empty the bucket
375-
4. Navigate to [CloudFormation Console](https://console.aws.amazon.com/cloudformation/)
376-
5. Select the `weather-agent-demo` stack
377-
6. Click "Delete"
378-
7. Confirm deletion
379-
380-
363+
4. Navigate to [Bedrock AgentCore Console](https://console.aws.amazon.com/bedrock-agentcore/)
364+
5. Go to "Browsers" in the left navigation
365+
6. Find your browser (name starts with `weather_agent_demo_browser`)
366+
7. Click on the browser name
367+
8. In the "Sessions" tab, terminate any active sessions
368+
9. Navigate to [CloudFormation Console](https://console.aws.amazon.com/cloudformation/)
369+
10. Select the `weather-agent-demo` stack
370+
11. Click "Delete"
371+
12. Confirm deletion
43.2 KB
Loading

04-cfn-samples/weather-agent-runtime/deploy.sh renamed to 04-infrastructure-as-code/cloudformation/end-to-end-weather-agent/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -e
88
# Configuration
99
STACK_NAME="${1:-weather-agent-demo}"
1010
REGION="${2:-us-west-2}"
11-
TEMPLATE_FILE="template.yaml"
11+
TEMPLATE_FILE="end-to-end-weather-agent.yaml"
1212

1313
echo "=========================================="
1414
echo "Deploying Weather Agent Runtime"

0 commit comments

Comments
 (0)