generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 519
Added the VPC Browser Examples #502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
evandrofranco
merged 6 commits into
awslabs:main
from
chintanpatel-ai:cjpatels-vpc-browser
Nov 4, 2025
+2,995
−29
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5327203
Added the VPC Browser Examples
chintanpatel-ai d24722b
Merge branch 'awslabs:main' into cjpatels-vpc-browser
chintanpatel-ai e751eec
ASH Fixes, error fixes for browse-use notebook
chintanpatel-ai abbedf4
Merge branch 'awslabs:main' into cjpatels-vpc-browser
chintanpatel-ai 088a922
updated the tech diagrams for VPC Browsers
chintanpatel-ai ef41edb
updated the numbering for VPC Browsers
chintanpatel-ai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
272 changes: 272 additions & 0 deletions
272
...blic-browser-from-private-vpc/01-connecting-public-browser-from-private-vpc-runtime.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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", | ||
| "" | ||
| ] | ||
| }, | ||
| { | ||
| "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)" | ||
evandrofranco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ] | ||
| }, | ||
| { | ||
| "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 | ||
| } | ||
Binary file added
BIN
+347 KB
...ser-tool/07-connecting-public-browser-from-private-vpc/architecture-browser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.