{ "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 }