@@ -186,41 +186,47 @@ def _destroy_ecr_images(
186
186
return
187
187
188
188
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 )
190
191
ecr_uri = agent_config .aws .ecr_repository
191
192
192
193
# Extract repository name from URI
193
194
# Format: account.dkr.ecr.region.amazonaws.com/repo-name
194
195
repo_name = ecr_uri .split ("/" )[- 1 ]
196
+
197
+ log .info ("Checking ECR repository: %s in region: %s" , repo_name , agent_config .aws .region )
195
198
196
199
try :
197
200
# List all images in the repository (both tagged and untagged)
198
201
response = ecr_client .list_images (repositoryName = repo_name )
202
+ log .debug ("ECR list_images response: %s" , response )
199
203
200
- all_images = response .get ("imageDetails" , [])
204
+ # Fix: use correct response key 'imageIds' instead of 'imageDetails'
205
+ all_images = response .get ("imageIds" , [])
201
206
if not all_images :
202
207
result .warnings .append (f"No images found in ECR repository: { repo_name } " )
203
208
return
204
209
205
210
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" )])
208
214
result .resources_removed .append (
209
215
f"ECR images in repository { repo_name } : { tagged_count } tagged, { untagged_count } untagged (DRY RUN)"
210
216
)
211
217
return
212
218
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
214
220
images_to_delete = []
215
221
216
222
for image in all_images :
217
- # Create image identifier for deletion
223
+ # imageIds structure already contains the correct identifiers
218
224
image_id = {}
219
225
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
224
230
elif image .get ("imageDigest" ):
225
231
image_id ["imageDigest" ] = image ["imageDigest" ]
226
232
@@ -284,7 +290,7 @@ def _destroy_codebuild_project(
284
290
) -> None :
285
291
"""Remove CodeBuild project for this agent."""
286
292
try :
287
- codebuild_client = session .client ("codebuild" )
293
+ codebuild_client = session .client ("codebuild" , region_name = agent_config . aws . region )
288
294
project_name = f"bedrock-agentcore-{ agent_config .name } -builder"
289
295
290
296
if dry_run :
@@ -320,7 +326,8 @@ def _destroy_iam_role(
320
326
return
321
327
322
328
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 )
324
331
role_arn = agent_config .aws .execution_role
325
332
role_name = role_arn .split ("/" )[- 1 ]
326
333
0 commit comments