concept mount target in category aws

This is an excerpt from Manning's book Amazon Web Services in Action, Second Edition.
EFS is not available from your resource group, unfortunately. Select EFS from the service menu to get more information about your NFS, as shown in figure 2.17. You can find the name, DNS name, and the mount targets of the filesystem in the Details section.
To make sure that the DNS name can be resolved and the other side is listening to the port, you can use the following Bash script to wait until the mount target is ready:
$ while ! nc -z $FileSystemID.efs.$Region.amazonaws.com 2049; do sleep 10; done $ sleep 10To use the filesystem, you have to mount it on EC2 instances using one of the mount targets that you created. It’s now time to add two EC2 instances to the CloudFormation template. Each EC2 instance should be placed in a different subnet and mount the filesystem to /home. The /home directory will exist on both EC2 instances, and it will also contain some data (such as the folder ec2-user). You have to ensure that you’re copying the original data the first time before you mount the EFS filesystem, which is empty by default. This listing describes the EC2 instance that copies the existing /home folder before the shared home folder is mounted.
An EFS mount target makes your data available to EC2 instances via the NFSv4.1 protocol in a single AZ. The EC2 instance communicates with the mount target via a TCP/IP network connection. As you learned in section 6.4, security groups are how you control network traffic on AWS. You can use a security group to allow inbound traffic to an EC2 instance or an RDS database, and the same is true for a mount target. Security groups control which traffic is allowed to enter the mount target. The NFS protocol uses port 2049 for inbound communication. Figure 10.3 shows how mount targets are protected.
In our example, to control traffic as tightly as possible, you won’t white list IP addresses. Instead, you’ll create two security groups. The client security group will be attached to all EC2 instances that want to mount the filesystem. The mount target security group allows inbound traffic on port 2049 only for traffic that comes from the client security group. This way, you can have a dynamic fleet of clients who are allowed to send traffic to the mount targets. You used the same approach for the SSH bastion host in section 6.4.
You can use CloudFormation to manage an EFS mount target. The mount target references the filesystem, needs to be linked to a subnet, and is also protected by at least one security group. You will first describe the security groups, followed by the mount target, as shown in listing 10.2.
Listing 10.2. CloudFormation snippet of an EFS mount target and security groups
Resources: [...] EFSClientSecurityGroup: #1 Type: 'AWS::EC2::SecurityGroup' Properties: GroupDescription: 'EFS Mount target client' VpcId: !Ref VPC MountTargetSecurityGroup: Type: 'AWS::EC2::SecurityGroup' Properties: GroupDescription: 'EFS Mount target' SecurityGroupIngress: - FromPort: 2049 #2 IpProtocol: tcp SourceSecurityGroupId: !Ref EFSClientSecurityGroup #3 ToPort: 2049 VpcId: !Ref VPC MountTargetA: Type: 'AWS::EFS::MountTarget' Properties: FileSystemId: !Ref FileSystem #4 SecurityGroups: - !Ref MountTargetSecurityGroup #5 SubnetId: !Ref SubnetA #6Copy the MountTargetA resource and also create a mount target for SubnetB.