You can pull data in advance from a data cache. Then, you can mount and use the data when you create elastic container instances. This topic describes the parameters that you use to create a data cache. This topic also describes how to create, query, update, copy, and delete a data cache.
Create a data cache
You can use one of the following methods to create a data cache:
API: You can call the CreateDataCache operation to create a data cache. For more information, see CreateDataCache.
Console: In the left-side navigation pane of the Elastic Container Instance console, click Data Cache. On the Data Cache page, click Create Data Cache. Configure the data cache parameters as needed and click OK.
Configuration description
When you create a data cache, you must configure the following parameters:
Basic properties
API
Console
Description
RegionId
Region
The region to which the data cache belongs.
Bucket
Cache Bucket
The bucket in which the data is stored. By default, the bucket named default is used. You can use a custom bucket to group business and prevent path conflicts.
The bucket named eci-system is reserved to store common caches of Elastic Container Instance and cannot be used as a value of this parameter.
Path
Cache Directory
The storage path of the data.
Name
Cache Name
The name of the data cache.
Size
Cache Size
The size of the data cache. Unit: GiB. Default value: 20. Evaluate the required size based on the actual data volume.
RetentionDays
Retention Period (Days)
The number of days for which the data cache is retained. When the retention days elapse, the data cache is deleted. By default, data caches do not expire.
Data source parameters
API
Console
Description
DataSource.Type
Type
The type of the data source.
DataSource.Options
Parameters
The parameters of the data source. This value is a JSON object. Different types of data sources require different parameters.
The following table describes various types of data sources and their parameters.
ImportantIf you create a data cache by calling an API operation, you must add the length of the parameter name before each parameter under the DataSource.Options parameter. For example, you must write
url
as#3#url
,repoId
as#6#repoId
, and repoSource as#10#repoSource
. If you create a data cache by using an SDK, this is not required.type
Description
options
URL
Hyperlink addresses
url: the URL from which data is downloaded.
accessToken: the token that is used for authentication before you pull private data.
HuggingFace or ModelScope
repoSource: pulls a model or dataset from the ModelScope or HuggingFace community. Valid values: ModelScope/Model, ModelScope/DataSet, HuggingFace/Model, and HuggingFace/DataSet.
repoId: the ID of the model or dataset.
revision: the version. Default value: main or master.
accessToken: the token that is used for authentication before you pull private data.
NAS
File Storage NAS (NAS) file systems
server: the mount target of the NAS file system.
path: the sub-directory of the NAS file system. For extreme NAS file systems, prefix
/share
to the path. Example:/share/path
.vers: the version number of the NFS (Network File System) protocol based on which the NAS file system is mounted. We recommend that you use NFS v3. Extreme NAS only supports NFS v3.
options: the parameters that are used when you set the type parameter to NAS. We recommend that you use the recommended parameters in the NAS service. Example:
nolock,tcp,noresvport
.
OSS
Object Storage Service (OSS) buckets
bucket: the name of the OSS bucket.
url: the endpoint of the OSS bucket.
path: the sub-directory of the OSS bucket. The path is relative to the root directory of the OSS bucket. Default value:
/
.otherOpts: The custom options that are specified to mount the OSS bucket. Format:
-o *** -o ***
. Example:-o max_stat_cache_size=0 -o allow_other
.ramRole: the Resource Access Management (RAM) role that is used if you use RAM to grant permissions.
NoteCreate a RAM role and grant the RAM role the permissions to access OSS buckets. For more information, see Create a RAM role for a trusted Alibaba Cloud service and Grant permissions to a RAM role.
When you create a RAM role, select Alibaba Cloud Service for the Select Trusted Entity parameter, Normal Service Role for the Role Type parameter, and Elastic Compute Service for the Select Trusted Service parameter. When you grant permissions to the RAM role, attach the AliyunOSSFullAccess policy to the RAM role.
akId: the AccessKey ID that is used if you use AccessKey pairs to grant permissions. For more information, see Obtain an AccessKey pair.
akSecret: the AccessKey secret that is used if you use AccessKey pairs to grant permissions. For more information, see Obtain an AccessKey pair.
SNAPSHOT
Snapshot
snapshotId: the ID of the snapshot.
Network parameters
If you want to pull data over the Internet, you can associate an elastic IP address (EIP) with the elastic container instance if the connected vSwitch is not configured with SNAT entries.
API
Console
Description
EipInstanceId
Use Existing
Associates an existing EIP with the elastic container instance.
Parameters under the EipCreateParam parameter.
Auto Create
Automatically creates an EIP and associates the EIP with the elastic container instance.
Other parameters
In addition to the preceding parameters, you must also configure parameters that are used to create temporary resources when you create a data cache, such as the parameters of a virtual private cloud (VPC), a vSwitch, and a security group.
Configuration examples
The following examples show how to create data caches of different types in API mode:
URL
Pull data from a URL
{ "RegionId": "cn-beijing", "SecurityGroupId": "sg-2ze63v3jtm8e6syi****", "VSwitchId": "vsw-2ze94pjtfuj9vaymf****", "Bucket": "test", "Path": "/demo/url", "Name": "test-url-1", "DataSource": { "Type": "URL", "Options": { "#10#url": "https://www.example.com" } }, "RetentionDays": 1 }
Pull a model from HuggingFace
{ "RegionId": "cn-beijing", "SecurityGroupId": "sg-2ze63v3jtm8e6syi****", "VSwitchId": "vsw-2ze94pjtfuj9vaymf****", "Bucket": "test", "Path": "/demo/url", "Name": "test-url-2", "DataSource": { "Type": "URL", "Options": { "#10#repoSource": "HuggingFace/Model", "#6#repoId": "stabilityai/stable-diffusion-2-1" } }, "RetentionDays": 1 }
NAS
{
"RegionId": "cn-beijing",
"SecurityGroupId": "sg-2ze63v3jtm8e6syi****",
"VSwitchId": "vsw-2ze94pjtfuj9vaymf****",
"Bucket": "test",
"Path": "/demo/nas",
"Name": "test-nas",
"DataSource": {
"Type": "NAS",
"Options": {
"#6#server": "126c24****-tw***.cn-beijing.nas.aliyuncs.com",
"#4#path": "/",
"#4#vers": "3",
"#7#options": "nolock,tcp,noresvport"
}
},
"RetentionDays": 1
}
OSS
{
"RegionId": "cn-beijing",
"SecurityGroupId": "sg-2ze63v3jtm8e6syi****",
"VSwitchId": "vsw-2ze94pjtfuj9vaymf****",
"Bucket": "test",
"Path": "/demo/oss",
"Name": "test-oss",
"DataSource": {
"Type": "OSS",
"Options": {
"#6#bucket": "test-***",
"#3#url": "oss-cn-beijing-internal.aliyuncs.com",
"#4#path": "/test",
"#9#otherOpts": "-o max_stat_cache_size=0 -o allow_other",
"#7#ramRole": "<your RAM Role Name>"
}
},
"RetentionDays": 1,
"SourceIp": "2401:b180:1000:3:a4ba:83d6:a4ba:83d6"
}
SNAPSHOT
{
"RegionId": "cn-beijing",
"SecurityGroupId": "sg-2ze63v3jtm8e6syi****",
"VSwitchId": "vsw-2ze94pjtfuj9vaymf****",
"Bucket": "test",
"Path": "/demo/snapshot",
"Name": "test-snapshot",
"DataSource": {
"Type": "SNAPSHOT",
"Options": {
"#10#snapshotId": "s-2zehb6jegdehec19****"
}
},
"RetentionDays": 1,
"Size": 40
}
Manage a data cache
Query a data cache
After you create a data cache, you can query the information about the data cache, such as the status, bucket, and storage path in the bucket. If the data cache is in the Available state, the data cache can be used.
You can use one of the following methods to query a data cache:
API: You can call the DescribeDataCaches operation to query the information about a data cache.
Console: On the Data Cache page, you can view all data caches in the selected region. You can click the ID of a data cache to view the information about the data cache.
Update a data cache
For a data cache in the Available or UpdateFailed state, you can update the bucket, data source, retention period, and size.
You can use one of the following methods to update a data cache:
API: You can call the UpdateDataCache operation to update a data cache.
Console: Not supported.
Copy a data cache
A data cache cannot be shared across regions. When you use a data cache to create an elastic container instance, if the elastic container instance that you want to create is not in the same region as the data cache, you can copy the data cache from the source region to the destination region.
You can use one of the following methods to copy a data cache to a different region:
API: You can call the CopyDataCache operation to copy a data cache.
Console: On the Data Cache page, find the data cache that you want to copy and click Copy in the Actions column.
Delete a data cache
A snapshot is created for each data cache. To retain a data cache, you are charged for the snapshot. If you do not specify a retention period for a data cache that is no longer needed, we recommend that you delete the data cache.
You can use one of the following methods to delete a data cache:
API: You can call the DeleteDataCache API operation to delete a data cache.
Console: On the Data Cache page, find the data cache that you want to delete and click Delete in the Actions column.