Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -7,6 +7,7 @@

import boto3
from boto3.session import Session
from botocore.exceptions import ClientError


def main():
Expand All @@ -31,23 +32,25 @@ def main():

try:
for ep in control.list_agent_runtime_endpoints(agentRuntimeId=runtime_id).get("runtimeEndpoints", []):
if ep["name"] == "DEFAULT":
continue # DEFAULT endpoint is auto-deleted with the runtime
control.delete_agent_runtime_endpoint(agentRuntimeId=runtime_id, endpointName=ep["name"])
time.sleep(30)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

try:
control.delete_agent_runtime(agentRuntimeId=runtime_id)
time.sleep(30)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

# Delete S3 code artifact
try:
bucket = f"agentcore-code-{account_id}-{region}"
s3.delete_object(Bucket=bucket, Key=f"{agent_name}/code.zip")
print(" Deleted S3 code artifact")
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

role_name = f"agentcore-{agent_name}-role"
Expand All @@ -56,8 +59,8 @@ def main():
for p in iam.list_role_policies(RoleName=role_name).get("PolicyNames", []):
iam.delete_role_policy(RoleName=role_name, PolicyName=p)
iam.delete_role(RoleName=role_name)
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")

if os.path.exists("runtime_config.json"):
os.remove("runtime_config.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import boto3
from boto3.session import Session
from botocore.exceptions import ClientError


def main():
Expand All @@ -31,23 +32,25 @@ def main():

try:
for ep in control.list_agent_runtime_endpoints(agentRuntimeId=runtime_id).get("runtimeEndpoints", []):
if ep["name"] == "DEFAULT":
continue # DEFAULT endpoint is auto-deleted with the runtime
control.delete_agent_runtime_endpoint(agentRuntimeId=runtime_id, endpointName=ep["name"])
time.sleep(30)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

try:
control.delete_agent_runtime(agentRuntimeId=runtime_id)
time.sleep(30)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

# Delete S3 code artifact
try:
bucket = f"agentcore-code-{account_id}-{region}"
s3.delete_object(Bucket=bucket, Key=f"{agent_name}/code.zip")
print(" Deleted S3 code artifact")
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

role_name = f"agentcore-{agent_name}-role"
Expand All @@ -56,8 +59,8 @@ def main():
for p in iam.list_role_policies(RoleName=role_name).get("PolicyNames", []):
iam.delete_role_policy(RoleName=role_name, PolicyName=p)
iam.delete_role(RoleName=role_name)
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")

if os.path.exists("runtime_config.json"):
os.remove("runtime_config.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import time

import boto3
from botocore.exceptions import ClientError

# ── Load Config ────────────────────────────────────────────────────────────────

Expand Down Expand Up @@ -49,19 +50,21 @@ def cleanup(config):
eps = control.list_agent_runtime_endpoints(agentRuntimeId=runtime_id)
for ep in eps.get("runtimeEndpoints", []):
ep_name = ep["name"]
control.delete_agent_runtime_endpoint(agentRuntimeId=runtime_id, name=ep_name)
if ep_name == "DEFAULT":
continue # DEFAULT endpoint is auto-deleted with the runtime
control.delete_agent_runtime_endpoint(agentRuntimeId=runtime_id, endpointName=ep_name)
print(f" Deleted endpoint: {ep_name}")
# Wait for deletion
time.sleep(10)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

# Delete runtime
print(f"Deleting AgentCore Runtime {runtime_id}...")
try:
control.delete_agent_runtime(agentRuntimeId=runtime_id)
print(" Runtime deletion initiated")
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

# Delete IAM role
Expand All @@ -72,15 +75,15 @@ def cleanup(config):
iam.delete_role_policy(RoleName=role_name, PolicyName=p)
iam.delete_role(RoleName=role_name)
print(f" Deleted role: {role_name}")
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

# Delete S3 artifacts
print(f"Deleting S3 object s3://{s3_bucket}/{s3_prefix}...")
try:
s3.delete_object(Bucket=s3_bucket, Key=s3_prefix)
print(" Deleted S3 object")
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

print("\nCleanup complete.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import boto3
from boto3.session import Session
from botocore.exceptions import ClientError


def main():
Expand All @@ -31,23 +32,25 @@ def main():

try:
for ep in control.list_agent_runtime_endpoints(agentRuntimeId=runtime_id).get("runtimeEndpoints", []):
if ep["name"] == "DEFAULT":
continue # DEFAULT endpoint is auto-deleted with the runtime
control.delete_agent_runtime_endpoint(agentRuntimeId=runtime_id, endpointName=ep["name"])
time.sleep(30)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

try:
control.delete_agent_runtime(agentRuntimeId=runtime_id)
time.sleep(30)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

# Delete S3 code artifact
try:
bucket = f"agentcore-code-{account_id}-{region}"
s3.delete_object(Bucket=bucket, Key=f"{agent_name}/code.zip")
print(" Deleted S3 code artifact")
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")

role_name = f"agentcore-{agent_name}-role"
Expand All @@ -56,8 +59,8 @@ def main():
for p in iam.list_role_policies(RoleName=role_name).get("PolicyNames", []):
iam.delete_role_policy(RoleName=role_name, PolicyName=p)
iam.delete_role(RoleName=role_name)
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")

if os.path.exists("runtime_config.json"):
os.remove("runtime_config.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import boto3
from boto3.session import Session
from botocore.exceptions import ClientError


def main():
Expand All @@ -29,32 +30,34 @@ def main():

try:
for ep in control.list_agent_runtime_endpoints(agentRuntimeId=runtime_id).get("runtimeEndpoints", []):
if ep["name"] == "DEFAULT":
continue # DEFAULT endpoint is auto-deleted with the runtime
control.delete_agent_runtime_endpoint(agentRuntimeId=runtime_id, endpointName=ep["name"])
time.sleep(30)
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")

try:
control.delete_agent_runtime(agentRuntimeId=runtime_id)
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")

# Delete S3 code artifact
try:
bucket = f"agentcore-code-{account_id}-{region}"
s3.delete_object(Bucket=bucket, Key=f"{agent_name}/code.zip")
print(" Deleted S3 code artifact")
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")

role_name = f"agentcore-{agent_name}-role"
iam = boto3.client("iam", region_name=region)
try:
for p in iam.list_role_policies(RoleName=role_name).get("PolicyNames", []):
iam.delete_role_policy(RoleName=role_name, PolicyName=p)
iam.delete_role(RoleName=role_name)
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")

if os.path.exists("runtime_config.json"):
os.remove("runtime_config.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import os
import sys
import time

import boto3
from boto3.session import Session
from botocore.exceptions import ClientError


def main():
Expand All @@ -27,29 +29,31 @@ def main():
print(f"Cleaning up: {agent_name}\n")
try:
for ep in control.list_agent_runtime_endpoints(agentRuntimeId=runtime_id).get("runtimeEndpoints", []):
if ep["name"] == "DEFAULT":
continue # DEFAULT endpoint is auto-deleted with the runtime
control.delete_agent_runtime_endpoint(agentRuntimeId=runtime_id, endpointName=ep["name"])
time.sleep(30)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")
try:
control.delete_agent_runtime(agentRuntimeId=runtime_id)
time.sleep(30)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")
try:
boto3.client("s3", region_name=region).delete_object(
Bucket=f"agentcore-code-{account_id}-{region}", Key=f"{agent_name}/code.zip"
)
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")
role_name = f"agentcore-{agent_name}-role"
iam = boto3.client("iam", region_name=region)
try:
for p in iam.list_role_policies(RoleName=role_name).get("PolicyNames", []):
iam.delete_role_policy(RoleName=role_name, PolicyName=p)
iam.delete_role(RoleName=role_name)
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")
if os.path.exists("runtime_config.json"):
os.remove("runtime_config.json")
print("✓ Cleanup complete")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import os
import sys
import time

import boto3
from boto3.session import Session
from botocore.exceptions import ClientError


def main():
Expand All @@ -27,29 +29,31 @@ def main():
print(f"Cleaning up: {agent_name}\n")
try:
for ep in control.list_agent_runtime_endpoints(agentRuntimeId=runtime_id).get("runtimeEndpoints", []):
if ep["name"] == "DEFAULT":
continue # DEFAULT endpoint is auto-deleted with the runtime
control.delete_agent_runtime_endpoint(agentRuntimeId=runtime_id, endpointName=ep["name"])
time.sleep(30)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")
try:
control.delete_agent_runtime(agentRuntimeId=runtime_id)
time.sleep(30)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")
try:
boto3.client("s3", region_name=region).delete_object(
Bucket=f"agentcore-code-{account_id}-{region}", Key=f"{agent_name}/code.zip"
)
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")
role_name = f"agentcore-{agent_name}-role"
iam = boto3.client("iam", region_name=region)
try:
for p in iam.list_role_policies(RoleName=role_name).get("PolicyNames", []):
iam.delete_role_policy(RoleName=role_name, PolicyName=p)
iam.delete_role(RoleName=role_name)
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")
if os.path.exists("runtime_config.json"):
os.remove("runtime_config.json")
print("✓ Cleanup complete")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import os
import sys
import time

import boto3
from boto3.session import Session
from botocore.exceptions import ClientError


def main():
Expand All @@ -27,29 +29,31 @@ def main():
print(f"Cleaning up: {agent_name}\n")
try:
for ep in control.list_agent_runtime_endpoints(agentRuntimeId=runtime_id).get("runtimeEndpoints", []):
if ep["name"] == "DEFAULT":
continue # DEFAULT endpoint is auto-deleted with the runtime
control.delete_agent_runtime_endpoint(agentRuntimeId=runtime_id, endpointName=ep["name"])
time.sleep(30)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")
try:
control.delete_agent_runtime(agentRuntimeId=runtime_id)
time.sleep(30)
except Exception as e:
except ClientError as e:
print(f" Warning: {e}")
try:
boto3.client("s3", region_name=region).delete_object(
Bucket=f"agentcore-code-{account_id}-{region}", Key=f"{agent_name}/code.zip"
)
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")
role_name = f"agentcore-{agent_name}-role"
iam = boto3.client("iam", region_name=region)
try:
for p in iam.list_role_policies(RoleName=role_name).get("PolicyNames", []):
iam.delete_role_policy(RoleName=role_name, PolicyName=p)
iam.delete_role(RoleName=role_name)
except Exception:
pass
except ClientError:
print(" Warning: cleanup resource not found or already deleted")
if os.path.exists("runtime_config.json"):
os.remove("runtime_config.json")
print("✓ Cleanup complete")
Expand Down
Loading
Loading