in rekognition/index-faces/index-faces.py [0:0]
def handler(event, context):
# Get the object from the event
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.parse.unquote_plus(
event['Records'][0]['s3']['object']['key'].encode('utf8'))
try:
# Calls Amazon Rekognition IndexFaces API to detect faces in S3 object
# to index faces into specified collection
response = index_faces(bucket, key)
# Commit faceId and full name object metadata to DynamoDB
if response['ResponseMetadata']['HTTPStatusCode'] == 200:
faceId = response['FaceRecords'][0]['Face']['FaceId']
ret = s3.head_object(Bucket=bucket,Key=key)
email = ret['Metadata']['email']
update_index(os.environ['COLLECTION_NAME'],faceId, email)
return response
except Exception as e:
print("Error processing object {} from bucket {}. ".format(key, bucket))
raise e