#!/usr/bin/env bash # Tear the demo down. Do this between rebuilds and after the recording so you # stop paying for Fargate / AgentCore. set -euo pipefail cd "$(dirname "$0")/.." REGION="${REGION:-us-east-1}" echo "==> Delete AgentCore Gateway + targets (not in Terraform state)" export AWS_PAGER="" GW_ID="$(aws bedrock-agentcore-control list-gateways --region "$REGION" \ --query "items[?name=='hncb-rag-gateway'].gatewayId | [0]" --output text 2>/dev/null || echo None)" if [ "$GW_ID" != "None" ] && [ -n "$GW_ID" ]; then for TID in $(aws bedrock-agentcore-control list-gateway-targets --region "$REGION" \ --gateway-identifier "$GW_ID" --query 'items[].targetId' --output text 2>/dev/null); do aws bedrock-agentcore-control delete-gateway-target --region "$REGION" \ --gateway-identifier "$GW_ID" --target-id "$TID" || true done aws bedrock-agentcore-control delete-gateway --region "$REGION" --gateway-identifier "$GW_ID" || true echo " deleted gateway $GW_ID" fi echo "==> Delete AgentCore Runtime + Memory (T5; not in Terraform state)" for RT in $(aws bedrock-agentcore-control list-agent-runtimes --region "$REGION" \ --query "agentRuntimes[?starts_with(agentRuntimeName,'hncb')].agentRuntimeId" --output text 2>/dev/null); do aws bedrock-agentcore-control delete-agent-runtime --region "$REGION" --agent-runtime-id "$RT" || true echo " deleted runtime $RT" done for MEM in $(aws bedrock-agentcore-control list-memories --region "$REGION" \ --query "memories[?starts_with(id,'hncb')].id" --output text 2>/dev/null); do aws bedrock-agentcore-control delete-memory --region "$REGION" --memory-id "$MEM" || true echo " deleted memory $MEM" done echo " (agentcore launch also auto-created an ECR repo, a CodeBuild project, and an" echo " AmazonBedrockAgentCoreSDKRuntime-* execution role -- delete by hand if desired.)" echo "==> Terraform destroy (DynamoDB, Lambda, ECS, IAM)" terraform -chdir=terraform destroy -auto-approve echo "==> Delete ECR repos (Presidio + the agentcore-built agent image; not in TF state)" for REPO in hncb-presidio bedrock-agentcore-hncb_advisor_agent; do aws ecr delete-repository --repository-name "$REPO" --force --region "$REGION" 2>/dev/null \ && echo " deleted ECR $REPO" || true done echo " (also free/leftover: the AmazonBedrockAgentCoreSDKRuntime-* role and a CodeBuild" echo " project agentcore created -- no cost idle; delete by hand if you want it spotless.)" echo "==> (manual) default VPC created by hand for the T1 live deploy (ap-southeast-1)" echo " Not in Terraform state; tagged maintenance=manual-cleanup-required. Free while" echo " empty, so usually leave it. To remove: aws ec2 delete-vpc --vpc-id vpc-0e97f4fdb643c3e26" echo "Teardown complete. (UI S3+CloudFront are Terraform-managed now, so the destroy" echo " above removes them; the S3 bucket has force_destroy=true.)"