2017-07-07 64 views
0

嘗試迭代通過AWS json輸出,並使用以下代碼檢查ECR中是否存在特定版本。但我總是得到「圖像不存在於ECR!」即使圖像標籤存在。迭代AWS json響應python

client = boto3.client('ecr') 
response = client.list_images(registryId='my_account_number', repositoryName='my_app') 

for i in response['imageIds']: 
    if i['imageTag'] != version: 
     print(response) 
     print('Image does not exist in ECR!') 
     quit() 
    else: 
     pass 
+2

'if''imageTag']!= version:'我認爲你的意思是'我['imageTag']'? – DeepSpace

+0

是的..調整了上述..相同的結果 – user2040074

+0

然後調試它。添加'print(i ['imageTag'])'。我們無法爲您調試,因爲我們沒有收到您的回覆。 – DeepSpace

回答

0

更改您的代碼運行,直到它找到您所期待的版本:如果沒有找到正確的版本,'Image does not exist in ECR!'將打印

client = boto3.client('ecr') 
response = client.list_images(registryId='my_account_number', repositoryName='my_app') 

for i in response['imageIds']: 
    if i['imageTag'] == version: 
     print('Found matching version!') 
     print(i) 
     break 
else: 
    print('Image does not exist in ECR!') 

+0

這工作!..感謝您的幫助。 – user2040074