in resource-selector-lambda/handler.py [0:0]
def getImage(self, config):
images=[]
if not self.imageOwner:
logger.error("Error: ImageOwner argument missing")
self.errorMessage = "ImageOwner argument missing"
self.setOutput(images)
self.error = 'failed'
return None
ec2 = boto3.resource('ec2', region_name=self.region)
for image in ec2.images.filter(Owners=[self.imageOwner]):
# if image name criteria provided
if self.imageName:
# check if it match with current image
if image.name and self.imageName in image.name:
#self.imageName in image.name:
# if image has tags, check if it macth with tag criteria
if image.tags:
if self.searchObject(image.tags, config):
images.append(image.id)
break
# if mo tag criteria provided, return image
elif not 'Tags' in config:
images.append(image.id)
break
# if no image name provided in configuration, check tag criteria only
elif image.tags and self.searchObject(image.tags, config):
images.append(image.id)
break
# if image doens't have tags and no tags criteria specified in configuration, return first image
elif images.append(image.id) and not 'Tags' in config:
images.append(image.id)
break
# turn list into a comma separated string and place it in our response
self.setOutput(images)