mirror of
https://github.com/awslabs/amazon-bedrock-agentcore-samples.git
synced 2025-09-08 20:50:46 +00:00
272 lines
7.4 KiB
Plaintext
272 lines
7.4 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "bc918d1b",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# 🧹 AgentCore End-to-End Cleanup\n",
|
||
|
"\n",
|
||
|
"This notebook provides a comprehensive cleanup process for all resources created during the AgentCore End-to-End tutorial.\n",
|
||
|
"\n",
|
||
|
"## Overview\n",
|
||
|
"\n",
|
||
|
"This cleanup process will remove:\n",
|
||
|
"- **Memory**: AgentCore Memory resources and stored data\n",
|
||
|
"- **Runtime**: Agent runtime instances and ECR repositories\n",
|
||
|
"- **Security**: Execution roles, and Authorization Provider resources\n",
|
||
|
"- **Observability**: CloudWatch log groups and streams\n",
|
||
|
"- **Local Files**: Generated configuration and code files\n",
|
||
|
"\n",
|
||
|
"⚠️ **Important**: This cleanup is irreversible. Make sure you have saved any important data (if needed) before proceeding.\n",
|
||
|
"\n",
|
||
|
"---"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "imports_header",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Step 1: Import Required Dependencies\n",
|
||
|
"\n",
|
||
|
"Load all necessary modules and helper functions for the cleanup process."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "imports",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import boto3\n",
|
||
|
"import os\n",
|
||
|
"from botocore.exceptions import ClientError\n",
|
||
|
"\n",
|
||
|
"from bedrock_agentcore_starter_toolkit import Runtime\n",
|
||
|
"from lab_helpers.lab2_memory import delete_memory, REGION\n",
|
||
|
"from lab_helpers.utils import (\n",
|
||
|
" delete_agentcore_runtime_execution_role,\n",
|
||
|
" delete_ssm_parameter,\n",
|
||
|
" cleanup_cognito_resources,\n",
|
||
|
" get_customer_support_secret,\n",
|
||
|
" delete_customer_support_secret,\n",
|
||
|
" agentcore_memory_cleanup,\n",
|
||
|
" gateway_target_cleanup,\n",
|
||
|
" runtime_resource_cleanup,\n",
|
||
|
" delete_observability_resources,\n",
|
||
|
" local_file_cleanup\n",
|
||
|
")\n",
|
||
|
"\n",
|
||
|
"print(\"✅ Dependencies imported successfully\")\n",
|
||
|
"print(f\"🌍 Working in region: {REGION}\")"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "memory_header",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Step 2: Clean Up Memory Resources\n",
|
||
|
"\n",
|
||
|
"Remove AgentCore Memory resources and associated data."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "16eda4ba",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"print(\"🧠 Starting Memory cleanup...\")\n",
|
||
|
"agentcore_memory_cleanup()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "runtime_header",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Step 3: Clean Up Runtime Resources\n",
|
||
|
"\n",
|
||
|
"Remove the AgentCore Runtime, ECR repository, and associated AWS resources."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "runtime_cleanup",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"print(\"🚀 Starting Runtime cleanup...\")\n",
|
||
|
"runtime_resource_cleanup()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "794ea1ca-f684-4790-a027-f99883a9b3da",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Step 4: Clean Up Gateway Resources\n",
|
||
|
"Remove targets, Gateway"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "3b697bc6-69f6-47cc-866e-f6f42de0e2c4",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"print(\"⚙️ Starting Gateway Cleanup...\")\n",
|
||
|
"gateway_target_cleanup()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "security_header",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Step 5: Clean Up Security Resources\n",
|
||
|
"\n",
|
||
|
"Remove execution roles, and authentication resources."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "security_cleanup",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"print(\"🛡️ Starting Security cleanup...\")\n",
|
||
|
"import json\n",
|
||
|
"try:\n",
|
||
|
" # bedrock_client = boto3.client(\"bedrock\", region_name=REGION)\n",
|
||
|
" \n",
|
||
|
" # Delete execution role\n",
|
||
|
" print(\" 🗑️ Deleting AgentCore Runtime execution role...\")\n",
|
||
|
" delete_agentcore_runtime_execution_role()\n",
|
||
|
" print(\" ✅ Execution role deleted\")\n",
|
||
|
" \n",
|
||
|
" # Delete SSM parameter\n",
|
||
|
" print(\" 🗑️ Deleting SSM parameter...\")\n",
|
||
|
" delete_ssm_parameter(\"/app/customersupport/agentcore/runtime_arn\")\n",
|
||
|
" print(\" ✅ SSM parameter deleted\")\n",
|
||
|
" \n",
|
||
|
" # Clean up Cognito and secrets\n",
|
||
|
" print(\" 🗑️ Cleaning up Cognito resources...\")\n",
|
||
|
" cs = json.loads(get_customer_support_secret())\n",
|
||
|
" cleanup_cognito_resources(cs['pool_id'])\n",
|
||
|
" print(\" ✅ Cognito resources cleaned up\")\n",
|
||
|
" \n",
|
||
|
" print(\" 🗑️ Deleting customer support secret...\")\n",
|
||
|
" delete_customer_support_secret()\n",
|
||
|
" print(\" ✅ Customer support secret deleted\")\n",
|
||
|
" \n",
|
||
|
"except Exception as e:\n",
|
||
|
" print(f\" ⚠️ Error during security cleanup: {e}\")"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "files_header",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Step 6: Clean Up Local Files\n",
|
||
|
"\n",
|
||
|
"Remove generated configuration and code files from the local directory."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "files_cleanup",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"print(\"📁 Starting Local Files cleanup...\")\n",
|
||
|
"local_file_cleanup()\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "observability_header",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Step 7: Clean Up Observability Resources\n",
|
||
|
"\n",
|
||
|
"Remove CloudWatch log groups and streams used for agent monitoring."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "7b7bc594",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"print(\"📊 Starting Observability cleanup...\")\n",
|
||
|
"\n",
|
||
|
"delete_observability_resources()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "completion_header",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## 🎉 Cleanup Complete!\n",
|
||
|
"\n",
|
||
|
"All AgentCore resources have been cleaned up. Here's a summary of what was removed:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "completion_summary",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"print(\"\\n\" + \"=\" * 60)\n",
|
||
|
"print(\"🧹 CLEANUP COMPLETED SUCCESSFULLY! 🧹\")\n",
|
||
|
"print(\"=\" * 60)\n",
|
||
|
"print()\n",
|
||
|
"print(\"📋 Resources cleaned up:\")\n",
|
||
|
"print(\" 🧠 Memory: AgentCore Memory resources and data\")\n",
|
||
|
"print(\" 🚀 Runtime: Agent runtime and ECR repository\")\n",
|
||
|
"print(\" 🛡️ Security: Roles, and SSM secrets\")\n",
|
||
|
"print(\" 📊 Observability: CloudWatch logs\")\n",
|
||
|
"print(\" 📁 Files: Local configuration files\")\n",
|
||
|
"print()\n",
|
||
|
"print(\"✨ Your AWS account is now clean and ready for new experiments!\")\n",
|
||
|
"print(\"\\nThank you for completing the AgentCore End-to-End tutorial! 🚀\")"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3 (ipykernel)",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"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.12.9"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 5
|
||
|
}
|