Skip to content

Commit 0a23494

Browse files
committed
fix: correct ECR API response format from imageDetails to imageIds
1 parent 8c0d866 commit 0a23494

File tree

1 file changed

+19
-12
lines changed
  • src/bedrock_agentcore_starter_toolkit/operations/runtime

1 file changed

+19
-12
lines changed

src/bedrock_agentcore_starter_toolkit/operations/runtime/destroy.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,41 +186,47 @@ def _destroy_ecr_images(
186186
return
187187

188188
try:
189-
ecr_client = session.client("ecr")
189+
# Create ECR client with explicit region specification
190+
ecr_client = session.client("ecr", region_name=agent_config.aws.region)
190191
ecr_uri = agent_config.aws.ecr_repository
191192

192193
# Extract repository name from URI
193194
# Format: account.dkr.ecr.region.amazonaws.com/repo-name
194195
repo_name = ecr_uri.split("/")[-1]
196+
197+
log.info("Checking ECR repository: %s in region: %s", repo_name, agent_config.aws.region)
195198

196199
try:
197200
# List all images in the repository (both tagged and untagged)
198201
response = ecr_client.list_images(repositoryName=repo_name)
202+
log.debug("ECR list_images response: %s", response)
199203

200-
all_images = response.get("imageDetails", [])
204+
# Fix: use correct response key 'imageIds' instead of 'imageDetails'
205+
all_images = response.get("imageIds", [])
201206
if not all_images:
202207
result.warnings.append(f"No images found in ECR repository: {repo_name}")
203208
return
204209

205210
if dry_run:
206-
tagged_count = len([img for img in all_images if img.get("imageTags")])
207-
untagged_count = len([img for img in all_images if not img.get("imageTags")])
211+
# Fix: imageIds structure has imageTag (string) not imageTags (array)
212+
tagged_count = len([img for img in all_images if img.get("imageTag")])
213+
untagged_count = len([img for img in all_images if not img.get("imageTag")])
208214
result.resources_removed.append(
209215
f"ECR images in repository {repo_name}: {tagged_count} tagged, {untagged_count} untagged (DRY RUN)"
210216
)
211217
return
212218

213-
# Prepare images for deletion - include all images in the agent's repository
219+
# Prepare images for deletion - imageIds are already in the correct format
214220
images_to_delete = []
215221

216222
for image in all_images:
217-
# Create image identifier for deletion
223+
# imageIds structure already contains the correct identifiers
218224
image_id = {}
219225

220-
# If image has tags, use the first tag
221-
if image.get("imageTags"):
222-
image_id["imageTag"] = image["imageTags"][0]
223-
# If no tags, use image digest
226+
# If image has a tag, use it
227+
if image.get("imageTag"):
228+
image_id["imageTag"] = image["imageTag"]
229+
# If no tag, use image digest
224230
elif image.get("imageDigest"):
225231
image_id["imageDigest"] = image["imageDigest"]
226232

@@ -284,7 +290,7 @@ def _destroy_codebuild_project(
284290
) -> None:
285291
"""Remove CodeBuild project for this agent."""
286292
try:
287-
codebuild_client = session.client("codebuild")
293+
codebuild_client = session.client("codebuild", region_name=agent_config.aws.region)
288294
project_name = f"bedrock-agentcore-{agent_config.name}-builder"
289295

290296
if dry_run:
@@ -320,7 +326,8 @@ def _destroy_iam_role(
320326
return
321327

322328
try:
323-
iam_client = session.client("iam")
329+
# Note: IAM is a global service, but we specify region for consistency
330+
iam_client = session.client("iam", region_name=agent_config.aws.region)
324331
role_arn = agent_config.aws.execution_role
325332
role_name = role_arn.split("/")[-1]
326333

0 commit comments

Comments
 (0)