Mounting an ephemeral disk to a function
Note
This feature is in the Preview stage. To get access, contact tech support
- In the management console
, select the folder containing the function. - Select Cloud Functions.
- Select a function.
- In the left-hand menu, select
Editor. - Under Ephemeral disk, click Add ephemeral disk and fill in these fields:
- Mount point: Name of the mount point. Use this path to access the directory in which the ephemeral disk is mounted:
/function/storage/<mount_point>
. - Disk size: Memory size you want to allocate for the ephemeral disk you are mounting.
- Mount point: Name of the mount point. Use this path to access the directory in which the ephemeral disk is mounted:
- Click Save changes.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To mount an ephemeral disk to a function, run this command:
yc serverless function version create \
--function-name=<function_name> \
--runtime <runtime_environment> \
--entrypoint <entry_point> \
--memory <RAM_size> \
--execution-timeout <execution_timeout> \
--source-path <path_to_ZIP_archive> \
--service-account-id <service_account_ID> \
--mount type=ephemeral-disk,mount-point=<mount_point>,size=<disk_size>
Where:
--function-name
: Function name.--runtime
: Runtime environment.--entrypoint
: Entry point in the following format:<file_name_without_extension>.<listener_name>
.--memory
: Amount of RAM.--execution-timeout
: Maximum function running time before the timeout is reached.--source-path
: ZIP archive with the function code and required dependencies.--service-account-id
: Service account ID.--mount
: Ephemeral disk mounting parameters:type=ephemeral-disk
: Type of the file system being mounted.mount-point
: Name of the mount point. Use this path to access the directory in which the disk is mounted:/function/storage/<mount_point>
.size
: Ephemeral disk size in GB, e.g.,size=5GB
.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the documentation on the Terraform
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To mount an ephemeral disk to a function:
-
Open the Terraform configuration file and add the
mounts
section to the function description:resource "yandex_function" "ephemeral_storage_function" { name = "<function_name>" user_hash = "<function_hash>" runtime = "<runtime_environment>" entrypoint = "<entry_point>" memory = "<RAM_size>" execution_timeout = "<execution_timeout>" service_account_id = "<service_account_ID>" content { zip_filename = "<path_to_ZIP_archive>" } mounts { name = "<mount_point>" ephemeral_disk { size_gb = <disk_size> } } }
Where:
mounts
: Ephemeral disk mounting parameters:name
: Name of the mount point. Use this path to access the directory in which the disk is mounted:/function/storage/<mount_point>
.size_gb
: Ephemeral disk size in GB, e.g.,size=5GB
.
For more information about the
yandex_function
resource parameters, see the provider documentation . -
Apply the changes:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
-
You can check the function update and its settings using the management console
yc serverless function version get <function_version_ID>
To mount an ephemeral disk to a function, use the createVersion REST API method for the Function resource or the FunctionService/CreateVersion gRPC API call.