Mounting an FSx for Lustre file system to a SageMaker Notebook Instance

Amazon FSx for Lustre is an excellent option to run workloads where speed matters. One of those scenarios is to train machine learning models.

FSx for Lustre integrates with Amazon S3 to transparently access files in a bucket as if they were locally available to your instance. The FSx file system will lazy-load data from the attached S3 bucket, and from that point forward, files will be directly accessible to your applications.

I'm going to assume that you can figure out how to set up an FSx for Lustre file system pointing to your S3 bucket, and focus the rest of this post on making it accessible to a SageMaker Notebook Instance.

I'd recommend creating a SageMaker Lifecycle Configuration to set up the file system every time the Notebook Instance starts. But you can do this manually too every time if you want.

Here is the script that you can use to set up the Lifecycle Configuration:


set -e

# This script mounts a FSx for Lustre file system to the Notebook 
# Instance at the /fsx directory based off the DNS and Mount name
# parameters.
# This script assumes the following:
#   1. There's an FSx for Lustre file system created and running
#   2. The FSx for Lustre file system is accessible from the 
#      Notebook Instance
#      - The Notebook Instance has to be created on the same VPN
#        as the FSx for Lustre file system
#      - The subnets and security groups have to be properly set up
#   3. Set the FSX_DNS_NAME parameter below to the DNS name of the 
#      FSx for Lustre file system.
#   4. Set the FSX_MOUNT_NAME parameter below to the Mount name of 
#      the FSx for Lustre file system.


# First, we need to install the lustre-client libraries
sudo yum install -y lustre-client

# Now we can create the mount point and mount the file system
sudo mkdir /fsx
sudo mount -t lustre \
    -o noatime,flock $FSX_DNS_NAME@tcp:/$FSX_MOUNT_NAME /fsx

# Let's make sure we have the appropriate access to the directory
sudo chmod go+rw /fsx

You have to make a couple of changes before saving this script:

  • FSX_DNS_NAME: This is the DNS name of the FSx file system.
  • FSX_MOUNT_NAME: This is the mount name of the FSx file system.

After setting those two parameters, the script does a few things:

  1. It installs the lustre-client library. As of the time of this writing, this library doesn't come pre-installed on Notebook Instances.
  2. It creates the directory where the file system will be mounted. The script is using /fsx for this, but you can change it to a different directory if you want.
  3. It mounts the file system using the DNS and Mount name parameters.
  4. Finally, it sets the appropriate permissions to the /fsx directory so you can read and write from it.

After saving the Lifecycle Configuration script, you can create a new Notebook Instance using this configuration. You also need to make sure your file system is accessible from the Notebook Instance. You can ensure this by creating the instance on the same VPN than the file system. Make sure you set up the subnets and security groups appropriately.

After the Notebook Instance starts, you can open the Jupyter Notebook's Terminal window and check that you have access to the contents of your S3 bucket inside the /fsx folder.