Use CreateMountTarget with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use CreateMountTarget with an AWS SDK or CLI

The following code examples show how to use CreateMountTarget.

CLI
AWS CLI

To create a mount target

The following create-mount-target example creates a mount target for the specified file system.

aws efs create-mount-target \ --file-system-id fs-c7a0456e \ --subnet-id subnet-02bf4c428bexample \ --security-groups sg-068f739363example

Output:

{ "OwnerId": "123456789012", "MountTargetId": "fsmt-f9a14450", "FileSystemId": "fs-c7a0456e", "SubnetId": "subnet-02bf4c428bexample", "LifeCycleState": "creating", "IpAddress": "10.0.1.24", "NetworkInterfaceId": "eni-02d542216aexample", "AvailabilityZoneId": "use2-az2", "AvailabilityZoneName": "us-east-2b", "VpcId": "vpc-0123456789abcdef0" }

For more information, see Creating mount targets in the Amazon Elastic File System User Guide.

PowerShell
Tools for PowerShell

Example 1: Creates a new mount target for a file system. The specified subnet will be used determine the Virtual Private Cloud (VPC) that the mount target will be created in and the IP address that will be auto-assigned (from the address range of the subnet). The assigned IP address can be used to then mount this file system on an Amazon EC2 instance. As no security groups were specified the network interface created for the target is associated with the default security group for the subnet's VPC.

New-EFSMountTarget -FileSystemId fs-1a2b3c4d -SubnetId subnet-1a2b3c4d

Output:

FileSystemId : fs-1a2b3c4d IpAddress : 10.0.0.131 LifeCycleState : creating MountTargetId : fsmt-1a2b3c4d NetworkInterfaceId : eni-1a2b3c4d OwnerId : 123456789012 SubnetId : subnet-1a2b3c4d

Example 2: Creates a new mount target for the specified file system with auto-assigned IP address. The network interface created for the mount target is associated with the specified security groups (up to 5, in the format "sg-xxxxxxxx", may be specified).

New-EFSMountTarget -FileSystemId fs-1a2b3c4d -SubnetId subnet-1a2b3c4d -SecurityGroup sg-group1,sg-group2,sg-group3

Example 3: Creates a new mount target for the specified file system with the specified IP address.

New-EFSMountTarget -FileSystemId fs-1a2b3c4d -SubnetId subnet-1a2b3c4d -IpAddress 10.0.0.131
  • For API details, see CreateMountTarget in AWS Tools for PowerShell Cmdlet Reference.