Samir
Posted on July 4, 2023
Introduction
In this blog post, we will walk you through the steps to create and mount an Amazon Elastic File System (EFS) on an AWS EC2 instance using the AWSSupport-CheckAndMountEFS system manager runbook. EFS provides scalable and shared file storage that can be accessed from multiple EC2 instances simultaneously.
Systems Manager Automation runbook
AWS Systems Manager provides predefined runbooks. These runbooks are maintained by Amazon Web Services, AWS Support, and AWS Config. The runbook reference describes each of the predefined runbooks provided by Systems Manager, AWS Support, and AWS Config.
AWSSupport-CheckAndMountEFS
The AWSSupport-CheckAndMountEFS runbook verifies the prerequisites to mount your Amazon Elastic File System (Amazon EFS) file system and mounts the file system on the Amazon Elastic Compute Cloud (Amazon EC2) instance you specify.
This runbook supports mounting your Amazon EFS file system with the DNS name, or using the mount target’s IP address.
Step 1: Create EFS from AWS Console
- Log in to the AWS Management Console and navigate to the EFS service.
- Click on "Create file system" and provide a name for your EFS.
- Choose the VPC where your EC2 instance resides.
- Select the "Regional" EFS option for high availability.
- (Optional) In the advanced options, you can choose the storage class. For example, you can select the "Standard" storage type instead of "Infrequent Access" (IA) if desired.
Step 2: Configure Network in EFS
- After the EFS creation, navigate to the EFS dashboard and go to the "Network" tab, then click on "Manage". Copy the security groups listed under "Mount targets" and navigate to the EC2 service, then go to "Security Groups".
- Add the EC2 instance's security group as a source under the EFS security group to allow access.
Step 3: Install EFS Utils
- Connect to your EC2 instance using SSH or AWS SSM.
- Run the following command based on your Linux distribution: For SUSE: zypper install aws-efs-utils For Amazon Linux 2: sudo yum install -y amazon-efs-utils
Step 4: Create EFS with AWS SSM Document
- Navigate to the AWS Systems Manager (SSM) service and go to "Documents".
- Search for "AWSSupport-CheckAndMountEFS" and select the corresponding document.
- Click on "Execute automation" in the top right corner.
- Choose "Simple execution".
- Provide the necessary input parameters: Choose your EC2 instance (only one instance allowed at a time). EfsId: Enter the EFS ID obtained from the EFS console. MountPoint: Specify the desired mount point (e.g., /usr/test). Region: Select your desired region. Action: Choose "CheckandMount".
- add your tags.
- Click on "Execute" to run the automation.
Step 5: Keep Mounted File After Reboot
In your EC2 server, navigate to the /etc/fstab file.
Add the following line, replacing the EFS ID and directory (/usr/test) with your own:
fs-0c1cf955858757bc7.efs.us-east-1.amazonaws.com:/ /usr/test efs defaults,_netdev 0 0
Step 6: Test EFS Mounting
To unmount the EFS, run the command: umount /usr/test.
Use the command "mount -a" to read the /etc/fstab file and mount all file systems listed in it.
Verify the mounted EFS by running the command: df -hT
Conclusion:
By following the above steps, you can create and mount an Amazon EFS on your AWS EC2 instance using the AWSSupport-CheckAndMountEFS system manager runbook. This enables you to leverage scalable and shared file storage for your applications.
Links:
https://docs.aws.amazon.com/systems-manager-automation-runbooks/latest/userguide/automation-awssupport-check-and-mount-efs.html
https://docs.aws.amazon.com/efs/latest/ug/automount-with-efs-mount-helper.html
Posted on July 4, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.