A JuiceFS Volume stores the mount configuration of an existing JuiceFS Enterprise Edition file system, so that the volume can be mounted by name when a Sandbox is created.
How it works
After the volume is created, the JuiceFS file system can be mounted by volume name when you create a Sandbox.
CreateVolume stores only the mount configuration. It does not create the JuiceFS file system or copy the data in the file system.
Prerequisites
-
A team is created in the Agent Sandbox console. For more information, see Create a team. Record the team ID.
-
A file system is created in the JuiceFS Enterprise Edition console, and you have the file system name, the access token, and the service endpoint. For more information, see Get started with JuiceFS Enterprise Edition.
-
A Virtual Private Cloud (VPC), a vSwitch, and a security group are prepared. The VPC must be able to connect to the JuiceFS service over the network. The example in this topic stores the configurations in the volume.
-
The Resource Access Management (RAM) identity that calls the volume API has the required permissions. For more information, see Grant a RAM user access to the console.
Procedure
Step 1: Install the SDK
This topic uses the Alibaba Cloud Python SDK to call the volume API operations. Install the SDK and configure the access credentials as described in Alibaba Cloud SDK and API Guide.
Step 2: Create a JuiceFS Volume
For more information about the request parameters, response parameters, and error codes, see CreateVolume - Create a volume.
Storage configuration
The fields of juiceFSVolumeConfig correspond to the Python SDK parameters as follows:
|
API field |
Python SDK field |
Required |
Description |
|
|
|
Yes |
The name of the existing JuiceFS file system. This parameter does not specify the name of the Agent Sandbox volume to create. |
|
|
|
Yes |
The service endpoint that the JuiceFS Enterprise Edition client uses to access the file system. |
|
|
|
No |
The remote directory to mount in the JuiceFS file system. The maximum length is 128 bytes. The example in this topic explicitly sets this parameter to |
|
|
|
Yes |
The access token of the JuiceFS file system. The maximum length is 256 bytes. The response of a volume query does not include this field. |
|
|
|
No |
The additional mount parameters passed to the JuiceFS client. The value is a string array. Do not specify the |
remoteDir specifies the remote directory in the JuiceFS file system, which is different from the local mount directory in the Sandbox. If you set the parameter to /datasets/project-a, the mounted content comes from this subdirectory. If the directory does not exist, the system creates the directory during the mount. Use a remote absolute path that starts with /, and make sure that the token has the permissions required to create and access the destination directory.
The platform converts remoteDir into the --subdir parameter of the JuiceFS client.
Do not print the request body, the JuiceFS token, or other credentials in logs.
Mount configuration
mountConfig.vpcConfig stores the VPC configurations required to access the JuiceFS service. The configurations are used when a Sandbox is created. The corresponding Python SDK parameter is mount_config.vpc_config, which is constructed by using models.CreateVolumeInputMountConfigVpcConfig.
|
API field |
Python SDK field |
Required |
Description |
|
|
|
Required if a VPC is configured |
The ID of the VPC that can access the JuiceFS service. |
|
|
|
Required if a VPC is configured |
The ID of the security group in the VPC. |
|
|
|
Required if a VPC is configured |
The IDs of the vSwitches in the VPC. Specify at least one vSwitch ID. |
mountConfig.vpcConfig is optional. If you configure the parameter, you must specify all the vpcId, securityGroupId, and vSwitchIds fields. The example in this topic stores the VPC configurations in the volume and reuses the configurations when a Sandbox is created. The VPC configurations can also be provided by using fc.sandbox.network.vpc in the metadata when you create a Sandbox. If the configurations are specified in both locations, the metadata takes precedence.
JuiceFS uses a token to access a file system. To mount JuiceFS, you do not need to configure mountConfig.role. The local mount directory in the Sandbox is specified by volume_mounts during the mount.
Environment variables
The following environment variables are read by the example in this topic. Configure the access credentials as described in the SDK instructions in Step 1, and set the other parameters in the creation example.
|
Environment variable |
Purpose |
Source or value |
|
|
The AccessKey ID used to call the volume API. |
Configure the access credentials of the calling identity as described in Alibaba Cloud SDK and API Guide. |
|
|
The AccessKey secret that matches the AccessKey ID. |
Obtain the secret together with the AccessKey ID. |
|
|
The security token used with Security Token Service (STS) temporary credentials. |
Set this variable only if you use STS temporary credentials. Use the token from the same set of temporary credentials. |
|
|
The region in which the volume API is called. |
Enter the ID of the destination region, such as |
|
|
The endpoint of the volume API. |
Enter |
|
|
The team that owns the volume. |
Obtain the ID of the destination team from the Agent Sandbox console. |
|
|
The name of the Agent Sandbox volume to create. |
Specify a name. The name must be unique within the team. The example uses |
|
|
The name of the existing JuiceFS file system. |
Obtain the name from the JuiceFS Enterprise Edition console. The value is different from the name of the Agent Sandbox volume. |
|
|
The service endpoint of JuiceFS Enterprise Edition. |
Enter the client access endpoint provided by the existing JuiceFS service. |
|
|
The token used to access the JuiceFS file system. |
Obtain the access token of the destination file system from the JuiceFS Enterprise Edition console. |
|
|
The remote directory to mount. |
Specify the directory based on the location of your data. The example uses |
|
|
The VPC used to access the JuiceFS service. |
Obtain the ID of the VPC that can connect to the JuiceFS service over the network from the VPC console. |
|
|
The security group used for the mount. |
Obtain the ID of a security group in the preceding VPC from the security group console. Make sure that the rules allow access to the JuiceFS service. |
|
|
The vSwitch used for the mount. |
Obtain the ID of a vSwitch in the preceding VPC from the VPC console. This example uses one vSwitch. |
Creation example
In a terminal in which the access credentials are configured, set the following parameters and replace the placeholders with actual values. For the value of each variable, see Environment variables in this topic.
export SANDBOX_REGION_ID="<REGION>"
export SANDBOX_ENDPOINT="sandbox.${SANDBOX_REGION_ID}.aliyuncs.com"
export SANDBOX_TEAM_ID="<TEAM-ID>"
export SANDBOX_VOLUME_NAME="juicefs-workspace"
export JUICEFS_VOLUME_NAME="<JUICEFS-FILE-SYSTEM-NAME>"
export JUICEFS_BASE_URL="https://<JUICEFS-SERVICE-ADDRESS>"
export JUICEFS_TOKEN="<JUICEFS-TOKEN>"
export JUICEFS_REMOTE_DIR="/"
export SANDBOX_VPC_ID="<VPC-ID>"
export SANDBOX_SECURITY_GROUP_ID="<SECURITY-GROUP-ID>"
export SANDBOX_VSWITCH_ID="<VSWITCH-ID>"
Save the following code as 01_create_juicefs_volume.py:
import os
from alibabacloud_sandbox20260820 import models
from alibabacloud_sandbox20260820.client import Client as SandboxClient
from alibabacloud_tea_openapi import utils_models as open_api_models
def require_env(name: str) -> str:
value = os.environ.get(name, "").strip()
if not value:
raise RuntimeError(f"Missing environment variable: {name}")
return value
config = open_api_models.Config(
access_key_id=require_env("ALIBABA_CLOUD_ACCESS_KEY_ID"),
access_key_secret=require_env("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
security_token=os.environ.get("ALIBABA_CLOUD_SECURITY_TOKEN"),
region_id=require_env("SANDBOX_REGION_ID"),
endpoint=require_env("SANDBOX_ENDPOINT"),
)
pop_client = SandboxClient(config)
response = pop_client.create_volume(
models.CreateVolumeRequest(
body=models.CreateVolumeInput(
team_id=require_env("SANDBOX_TEAM_ID"),
volume_name=require_env("SANDBOX_VOLUME_NAME"),
mount_config=models.CreateVolumeInputMountConfig(
vpc_config=models.CreateVolumeInputMountConfigVpcConfig(
vpc_id=require_env("SANDBOX_VPC_ID"),
security_group_id=require_env("SANDBOX_SECURITY_GROUP_ID"),
v_switch_ids=[require_env("SANDBOX_VSWITCH_ID")],
),
),
juice_fsvolume_config=models.JuiceFSVolumeConfig(
volume_name=require_env("JUICEFS_VOLUME_NAME"),
base_url=require_env("JUICEFS_BASE_URL"),
remote_dir=require_env("JUICEFS_REMOTE_DIR"),
token=require_env("JUICEFS_TOKEN"),
args=[],
),
)
)
)
if response.body is None or response.body.volume is None:
raise RuntimeError("CreateVolume did not return a volume")
volume = response.body.volume
print(f"request_id={response.body.request_id}")
print(f"volume_id={volume.volume_id}")
print(f"volume_name={volume.volume_name}")
print(f"storage_class={volume.storage_class}")
print(f"status={volume.status}")
Run the script in the same terminal:
python 01_create_juicefs_volume.py
CreateVolume does not check the network connectivity of the JuiceFS service, and does not perform the actual mount. Create a Sandbox as described in Mount a JuiceFS Volume, and confirm that the mount is available by reading and writing data.
Manage volumes
Query the volume list by using ListVolumes, view the details of a volume by using GetVolume. Update the volume configuration by using UpdateVolume, and delete volumes that are no longer in use by using DeleteVolume.
Deleting a volume removes only the mount configuration on the Agent Sandbox side. The JuiceFS file system and the data in the file system are not deleted.
Limits
-
A JuiceFS Volume supports only JuiceFS Enterprise Edition file systems.
-
Volume names must be unique within a team.
FAQ
Why does CreateVolume report that exactly one storage configuration is required?
If the error message is request must contain exactly one volume config, the request does not contain a storage configuration, or the request contains storage configurations of multiple types. To create a JuiceFS Volume, provide juiceFSVolumeConfig only, and do not provide configurations for other storage types.
mountConfig.vpcConfig stores the VPC configurations required for the mount, and cannot replace the file system name, service endpoint, and token in juiceFSVolumeConfig. For more information about the fields, see Storage configuration in this topic.
Why does CreateVolume report that the volume name already exists?
If the response returns VolumeConflict and the error message contains already exists, a volume that has the same name already exists in the team. Query the configuration and status of the volume to check whether the volume can be reused. If an independent resource is required, use another name.
Why does CreateVolume report that the team cannot be found?
If the response returns TeamNotFound, check the teamID, the account to which the calling credentials belong, and the region of the request. Make sure that the destination team exists and belongs to the current account.
CreateVolume is denied. Which identity should be granted permissions?
Check whether the RAM identity that calls the API operation has the sandbox:CreateVolume permission, and whether the authorization scope covers the destination team. For more information about how to grant permissions, see Grant a RAM user access to the console.
The JuiceFS token is used to access the file system, and cannot replace the RAM permissions required to call the volume API.
To troubleshoot the issue further, retain the complete error message and the request ID.