You can test Amazon Rekognition Face Liveness with any supported AWS SDK , like the AWS Python SDK Boto3 or the
AWS
SDK for Java. You can call the CreateFaceLivenessSession
and
GetFaceLivenessSessionResults
APIs with your chosen SDK. The following
section demonstrates how to call these APIs with the Python and Java SDKs.
To call the Face Liveness APIs:
-
If you haven't already, create or update a user with
AmazonRekognitionFullAccess
permissions. For more information, see Step 1: Set up an AWS account and create a User. -
If you haven't already, install and configure the AWS CLI and the AWS SDKs. For more information, see Step 2: Set up the AWS CLI and AWS SDKs.
The following snippet shows how you can call these APIs in your Python applications. Note that to run this example you will need to be using at least version 1.26.110 of the Boto3 SDK, although the most recent version of the SDK is recommended.
import boto3
session = boto3.Session(profile_name='default')
client = session.client('rekognition')
def create_session():
response = client.create_face_liveness_session()
session_id = response.get("SessionId")
print('SessionId: ' + session_id)
return session_id
def get_session_results(session_id):
response = client.get_face_liveness_session_results(SessionId=session_id)
confidence = response.get("Confidence")
status = response.get("Status")
print('Confidence: ' + "{:.2f}".format(confidence) + "%")
print('Status: ' + status)
return status
def main():
session_id = create_session()
print('Created a Face Liveness Session with ID: ' + session_id)
status = get_session_results(session_id)
print('Status of Face Liveness Session: ' + status)
if __name__ == "__main__":
main()