code: def handle_s3_file_path(path):
      import sys
  
      if sys.version_info.major == 2:
          import urlparse
  
          parse_cmd = urlparse.urlparse
      else:
          import urllib
  
          parse_cmd = urllib.parse.urlparse
  
      import boto3
      from botocore.exceptions import ClientError
  
      # parse the path
      parsed_url = parse_cmd(path)
  
      # get S3 client
      s3 = boto3.resource("s3")
  
      # read file content and pass it down
      obj = s3.Object(parsed_url.netloc, parsed_url.path.lstrip("/"))
      print("loading file: " + str(obj))
  
      try:
          data = obj.get()["Body"]
      except ClientError as ce:
          raise ValueError(
              "Can't download from S3 path: "
              + path
              + " : "
              + ce.response["Error"]["Message"]
          )
  
      import StringIO
  
      buf = StringIO(data.read())
      img = gzip.GzipFile(mode="rb", fileobj=buf)
  
      _, _, rows, cols = struct.unpack(">IIII", img.read(16))
      images = np.fromstring(img.read(), dtype=np.uint8).reshape(
          10000, rows, cols
      )
      images = (
          images.reshape(images.shape[0], 1, 28, 28).astype(np.float32)
          / 255
      )
  
      return mx.io.NDArrayIter(images, None, 1)
  
file_path: sagemaker-python-sdk/tests/data/mxnet_mnist/mnist_hosting_with_custom_handlers.py
imports: from __future__ import absolute_import
  import gzip
  import json
  import mxnet
  import numpy
  import os
  import struct
label_desc: Use image node_id 4 for calling a global function with example usage: handle_s3_file_path(path) and returns: mx