in src/rekognition/index-faces/handler.py [0:0]
def function_main(event:Mapping[str,Any],_=None):
'''
Main function handler.
'''
face_metadata = FaceMetadata(event)
'''
Index the face into the Amazon Rekognition Collection.
'''
try:
response = rek_client.index_faces(
CollectionId = get_collection_id(face_metadata.user_id),
ExternalImageId= face_metadata.user_id,
MaxFaces=1,
Image={
'Bytes':face_metadata.image_bytes
})
except Exception as error:
print('Unable to update collection')
raise error
'''
Write the metadata and image content
'''
if not len(response['FaceRecords']) == 1:
raise NotImplementedError('This sample only supports one indexed face.')
face_record = response['FaceRecords'][0]
face_id = face_record['Face']['FaceId']
storage_writer.persist(face_metadata, face_id)
'''
Return a response
'''
return {
'FaceModelVersion': response['FaceModelVersion'],
'FaceRecord': face_record
}