def __get_image_from_uri()

in src/rekognition/compare-faces/ddb.py [0:0]


  def __get_image_from_uri(self, s3_uri:str)->bytes:
    '''
    Downloads the requested image from Amazon S3.
    :param s3_uri: The path in format s3://bucket/key.
    :rtype: The raw image bytes.
    '''
    #xray_recorder.current_subsegment().put_annotation('s3_uri', s3_uri)
    url = urlparse(s3_uri)

    if url.scheme != 's3':
      raise InvalidImageUriException(
        'get_image_from_uri only supports s3://bucket/key format.')

    bucket = url.netloc
    key = url.path.lstrip('/')

    if not key.lower().endswith('.png') and not key.lower().endswith('.jpg'):
      raise InvalidImageExtensionException(
        'get_image_from_uri only supports .png and .jpg files.')

    '''
    Retrieve the object from the bucket.
    '''
    response = self.s3.get_object(Bucket=bucket,Key=key)
    return response['Body'].read()