AWS Rekognition on AWS Lambda

83 views Asked by At

I have been trying to use Boto3 on AWS Lambda for faceliveness detection according to this docs https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rekognition.html

But I keep getting:

{
  "errorMessage": "'Rekognition' object has no attribute 'create_face_liveness_session'",
  "errorType": "AttributeError",
  "requestId": "349cb11a-9372-4e5e-b46d-95ecceff085a",
  "stackTrace": [
    "  File \"/var/task/RecogniseTest-6ed843a6-e80f-42bf-9c05-ed0507222161/lambda_function.py\", line 40, in lambda_handler\n    raise e\n",
    "  File \"/var/task/RecogniseTest-6ed843a6-e80f-42bf-9c05-ed0507222161/lambda_function.py\", line 34, in lambda_handler\n    response = create_liveness_session(request_token)\n",
    "  File \"/var/task/RecogniseTest-6ed843a6-e80f-42bf-9c05-ed0507222161/lambda_function.py\", line 17, in create_liveness_session\n    response = rekognition.create_face_liveness_session(\n",
    "  File \"/var/runtime/botocore/client.py\", line 876, in __getattr__\n    raise AttributeError(\n"
  ]
}

Meanwhile, create_face_liveness_session() is in the documentation.

My implementation:

import boto3
from decimal import Decimal
import json
import urllib.request
import urllib.parse
import urllib.error

print('Loading function')

rekognition = boto3.client('rekognition')

print(dir(rekognition))
# --------------- Helper Functions to call Rekognition APIs ------------------


def create_liveness_session(request_token):
    response = rekognition.create_face_liveness_session(
        ClientRequestToken=request_token
    )
    print(response)
    return response


# --------------- Main handler ------------------


def lambda_handler(event, context):
    print(event)
    if not 'body' in event:
        try:
            # request_body = json.loads(event['body'])
            request_token = event.get('request_token')
            print("Request Token: ", request_token)
            response = create_liveness_session(request_token)

            return response

        except Exception as e:
            print(e)
            raise e

Please help. Thanks

I was expecting to get sessionId after calling create_face_liveness_session().

Below are the available methods which goes against the documentation:

['_PY_TO_OP_NAME', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_cache', '_client_config', '_convert_to_request_dict', '_emit_api_params', '_endpoint', '_exceptions', '_exceptions_factory', '_get_waiter_config', '_load_exceptions', '_loader', '_make_api_call', '_make_request', '_register_handlers', '_request_signer', '_resolve_endpoint_ruleset', '_response_parser', '_ruleset_resolver', '_serializer', '_service_model', 'can_paginate', 'close', 'compare_faces', 'copy_project_version', 'create_collection', 'create_dataset', 'create_project', 'create_project_version', 'create_stream_processor', 'delete_collection', 'delete_dataset', 'delete_faces', 'delete_project', 'delete_project_policy', 'delete_project_version', 'delete_stream_processor', 'describe_collection', 'describe_dataset', 'describe_project_versions', 'describe_projects', 'describe_stream_processor', 'detect_custom_labels', 'detect_faces', 'detect_labels', 'detect_moderation_labels', 'detect_protective_equipment', 'detect_text', 'distribute_dataset_entries', 'exceptions', 'generate_presigned_url', 'get_celebrity_info', 'get_celebrity_recognition', 'get_content_moderation', 'get_face_detection', 'get_face_search', 'get_label_detection', 'get_paginator', 'get_person_tracking', 'get_segment_detection', 'get_text_detection', 'get_waiter', 'index_faces', 'list_collections', 'list_dataset_entries', 'list_dataset_labels', 'list_faces', 'list_project_policies', 'list_stream_processors', 'list_tags_for_resource', 'meta', 'put_project_policy', 'recognize_celebrities', 'search_faces', 'search_faces_by_image', 'start_celebrity_recognition', 'start_content_moderation', 'start_face_detection', 'start_face_search', 'start_label_detection', 'start_person_tracking', 'start_project_version', 'start_segment_detection', 'start_stream_processor', 'start_text_detection', 'stop_project_version', 'stop_stream_processor', 'tag_resource', 'untag_resource', 'update_dataset_entries', 'update_stream_processor', 'waiter_names']
0

There are 0 answers