Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "72ae9ba9",
"metadata": {},
"source": [
"## Use Case: Hybrid Deployment Architecture\n",
"\n",
"### Scenario: Secure Data Processing with Internet Access\n",
"\n",
"In this deployment pattern, we separate the AgentCore components to balance security and functionality:\n",
"\n",
"**AgentCore Browser (Public Mode)**\n",
"- Deployed in public subnets with internet access\n",
"- Enables web browsing of publicly accessible websites and services\n",
"- Manages external integrations and real-time data retrieval\n",
"- Benefits from direct internet connectivity for real-time operations\n",
"\n",
"**AgentCore Runtime (VPC Mode)**\n",
"- Deployed in private subnets within a secure VPC\n",
"- Processes sensitive data and business logic\n",
"- Maintains strict network isolation\n",
"- Communicates with browser component through secure internal channels\n",
"\n",
"### Benefits\n",
"\n",
"- **Security**: Sensitive processing remains isolated in private network\n",
"- **Performance**: Browser operations get direct internet access without NAT overhead\n",
"- **Compliance**: Meets regulatory requirements for data isolation\n",
"- **Scalability**: Each component can scale independently based on workload demands\n",
"\n",
"### Architecture Flow\n",
"\n",
"![image.png](architecture-browser.png)"
]
},
{
"cell_type": "markdown",
"id": "e878046c",
"metadata": {},
"source": [
"# CloudFormation Stack Execution Instructions\n",
"\n",
"## Prerequisites\n",
"- AWS CLI configured with appropriate permissions\n",
"- CloudFormation template file ready"
]
},
{
"cell_type": "markdown",
"id": "cb9e8af7",
"metadata": {},
"source": [
"## Execution Steps"
]
},
{
"cell_type": "markdown",
"id": "0cfac78b",
"metadata": {},
"source": [
"### 1. Run below the step to launch CFN (~ 10 mins)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1bda7418",
"metadata": {},
"outputs": [],
"source": [
"import boto3\n",
"import yaml\n",
"import os\n",
"\n",
"# Configuration variables\n",
"region = 'us-east-1' # Change this to your desired region\n",
"template_path = 'cfn-browser.yaml'\n",
"stack_name = 'browser-stack'\n",
"\n",
"# Initialize CloudFormation client with configurable region\n",
"cf_client = boto3.client('cloudformation', region_name=region)\n",
"\n",
"# Read the CloudFormation template\n",
"with open(template_path, 'r') as template_file:\n",
" template_body = template_file.read()\n",
"\n",
"try:\n",
" # Create the CloudFormation stack\n",
" response = cf_client.create_stack(\n",
" StackName=stack_name,\n",
" TemplateBody=template_body,\n",
" Capabilities=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM']\n",
" )\n",
" \n",
" print(f\"Stack creation initiated in region: {region}\")\n",
" print(f\"Stack ID: {response['StackId']}\")\n",
" \n",
" # Wait for stack creation to complete\n",
" waiter = cf_client.get_waiter('stack_create_complete')\n",
" print(\"Waiting for stack creation to complete...\")\n",
" waiter.wait(StackName=stack_name)\n",
" \n",
" print(f\"Stack '{stack_name}' created successfully in {region}!\")\n",
" \n",
"except Exception as e:\n",
" print(f\"Error creating stack: {str(e)}\")"
]
},
{
"cell_type": "markdown",
"id": "9ceca4b1",
"metadata": {},
"source": [
"### 2. Instructions for Testing"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "176b7eb2",
"metadata": {},
"outputs": [],
"source": [
"import boto3\n",
"import subprocess\n",
"import json\n",
"from IPython.display import display, Markdown\n",
"\n",
"# Fetch AgentRuntime ARN from CloudFormation output\n",
"def get_cfn_output(stack_name, output_key, region='us-east-1'):\n",
" \"\"\"Fetch CloudFormation stack output value\"\"\"\n",
" cfn = boto3.client('cloudformation', region_name=region)\n",
" try:\n",
" response = cfn.describe_stacks(StackName=stack_name)\n",
" outputs = response['Stacks'][0]['Outputs']\n",
" for output in outputs:\n",
" if output['OutputKey'] == output_key:\n",
" return output['OutputValue']\n",
" except Exception as e:\n",
" print(f\"Error fetching CFN output: {e}\")\n",
" return None\n",
"\n",
"# Get the AgentRuntime ARN (using stack_name from previous cell)\n",
"agent_runtime_arn = get_cfn_output(stack_name, 'AgentRuntimeArn')\n",
"agent_runtime_id = get_cfn_output(stack_name, 'AgentRuntimeId')\n",
"development_instance = get_cfn_output(stack_name, 'DevelopmentInstanceId')\n",
"\n",
"\n",
"# Generate complete testing instructions\n",
"instructions = f\"\"\"# Testing Instructions for Bedrock Agent Runtime\n",
"\n",
"## Prerequisites\n",
"- CloudFormation stack has been completed successfully\n",
"\n",
"## Step-by-Step Testing Process\n",
"\n",
"### 1. Connect to EC2 Instance\n",
"Connect to EC2 instance `{development_instance}` via Browser Connector or SSH\n",
"\n",
"### 2. Setup Environment\n",
"Run the following commands on the EC2 instance:\n",
"\n",
"```bash\n",
"sudo yum update -y\n",
"\n",
"# Install development tools\n",
"sudo dnf install git -y && \\\\\n",
"curl -LsSf https://astral.sh/uv/install.sh | sh && \\\\\n",
"echo 'export PATH=\"$HOME/.cargo/bin:$PATH\"' >> ~/.bashrc && \\\\\n",
"source ~/.bashrc && \\\\\n",
"echo 'Install Python Venv'\n",
"\n",
"uv init vpc-browser --python 3.13 && cd vpc-browser\n",
"uv venv --python 3.13\n",
"source .venv/bin/activate\n",
"uv pip install boto3\n",
"\n",
"cat > call-agent.py << 'EOF'\n",
"import boto3\n",
"import json\n",
"\n",
"client = boto3.client('bedrock-agentcore', region_name='us-east-1')\n",
"\n",
"payload = json.dumps({{\n",
" \"prompt\": \"What is the Weather in Richmond VA Today?\"\n",
"}})\n",
"\n",
"response = client.invoke_agent_runtime(\n",
" agentRuntimeArn=\"{agent_runtime_arn}\",\n",
" runtimeSessionId='dfmeoagmreaklgmrkleafremoigrmtesogmtrskhmtkrlshmt', # Must be 33+ chars\n",
" payload=payload,\n",
" qualifier=\"DEFAULT\" # Optional\n",
")\n",
"\n",
"response_body = response['response'].read()\n",
"response_data = json.loads(response_body)\n",
"print(\"Agent Response:\", response_data)\n",
"EOF\n",
"\n",
"\n",
"```\n",
"\n",
"### 3 Run the agent test\n",
"```\n",
"python call-agent.py\n",
"```\n",
"\n",
"### 4. Monitor logs in CloudWatch:\n",
"- Navigate to CloudWatch Logs in the AWS Console\n",
"- Look for log group: /aws/bedrock-agentcore/runtimes/{agent_runtime_id}\n",
"- To view live browsing go to console -> Amazon Bedrock AgentCore -> Built-in Tools -> Browser tools -> browser_stack_browser -> View live session\n",
"- Monitor real-time execution logs and any errors\n",
"\n",
"\"\"\"\n",
"\n",
"Markdown(instructions)"
]
},
{
"cell_type": "markdown",
"id": "685d34ec",
"metadata": {},
"source": [
"### 3. Clean up"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc7dc02a",
"metadata": {},
"outputs": [],
"source": [
"import boto3\n",
"\n",
"# Delete the stack\n",
"cfn = boto3.client('cloudformation', region_name=region)\n",
"cfn.delete_stack(StackName=stack_name)\n",
"\n",
"print(f\"Stack '{stack_name}' deletion initiated in region '{region}'\")\n",
"\n",
"# Wait for deletion to complete\n",
"waiter = cfn.get_waiter('stack_delete_complete')\n",
"print(\"Waiting for stack deletion to complete...\")\n",
"waiter.wait(StackName=stack_name)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "",
"language": "python",
"name": ""
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading