Example: Use an EFS file system as a shared home directory for AWS PCS - AWS PCS

Example: Use an EFS file system as a shared home directory for AWS PCS

Provide this script as the value of "userData" in your launch template. For more information, see Working with Amazon EC2 user data.

This example extends the example EFS mount in Using network file systems with AWS PCS to implement a shared home directory. The contents of /home are backed up before the EFS file system is mounted. The contents are then quickly copied into place on the shared storage after the mount completes.

Replace the following values in this script with your own details:

  • /mount-point-directory – The path on an instance where you want to mount the EFS file system.

  • filesystem-id – The file system ID for the EFS file system.

MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==MYBOUNDARY==" --==MYBOUNDARY== Content-Type: text/cloud-config; charset="us-ascii" packages: - amazon-efs-utils runcmd: - mkdir -p /tmp/home - rsync -a /home/ /tmp/home - echo "filesystem-id:/ /mount-point-directory efs tls,_netdev" >> /etc/fstab - mount -a -t efs defaults - rsync -a --ignore-existing /tmp/home/ /home - rm -rf /tmp/home/ --==MYBOUNDARY==--

Enabling passwordless SSH

You can build on the shared home directory example to implement SSH connections between cluster instances using SSH keys. For each user using the shared home file system, run a script that resembles the following:

#!/bin/bash mkdir -p $HOME/.ssh && chmod 700 $HOME/.ssh touch $HOME/.ssh/authorized_keys chmod 600 $HOME/.ssh/authorized_keys if [ ! -f "$HOME/.ssh/id_rsa" ]; then ssh-keygen -t rsa -b 4096 -f $HOME/.ssh/id_rsa -N "" cat ~/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys fi
Note

The instances must use a security group that allows SSH connections between cluster nodes.