Mounting buckets to a function
You can mount Yandex Object Storage buckets to a function. Mounting a bucket automatically creates a new function version.
To mount buckets to a function:
-
In the management console
, navigate to the folder containing the function. -
Go to Cloud Functions.
-
Select the function.
-
Navigate to the Editor tab.
-
In the Parameters section, select or create a service account with one of these roles:
storage.viewerto only read data from the mounted bucket.storage.uploaderto read and write data from/to the mounted bucket.
-
Expand Additional settings.
-
Under Mounted buckets:
-
Click Add bucket.
-
Specify the following:
- Mount point: Name of the mount point. The directory with the mounted bucket will be accessible at
/function/storage/<mount_point>. - Bucket: Bucket you want to mount. If necessary, create a new bucket.
- Directory: Bucket folder that will be mounted to the container. Leave this field empty to mount the entire bucket.
- Mount point: Name of the mount point. The directory with the mounted bucket will be accessible at
-
Enable Read-only to prevent writing to the bucket. With this option enabled, data from the mounted bucket will be read-only.
To mount an additional bucket to the function, click Add bucket again and configure the settings as needed.
-
-
Click Save changes.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
Run this command:
yc serverless function version create \
--function-name=<function_name> \
--runtime <runtime> \
--entrypoint <entry_point> \
--memory <RAM_amount> \
--execution-timeout <execution_timeout> \
--source-path <path_to_ZIP_archive> \
--service-account-id <service_account_ID> \
--mount type=object-storage,mount-point=<mount_point>,bucket=<bucket_name>,prefix=<folder_name>,mode=<mount_mode>
Where:
-
--function-name: Function name. -
--runtime: Function runtime. -
entrypoint: Entry point in<file_name_without_extension>.<handler_name>format, e.g.,index.handler. -
--memory: Amount of RAM. -
--execution-timeout: Maximum function execution time before timeout. -
--source-path: Path to the ZIP archive with the function code and required dependencies. -
--service-account-id: Service account ID. The service account needs thestorage.viewerrole for bucket read access or thestorage.uploaderrole for both read and write access. -
--mount: Object Storage bucket mount settings:type: Mounted storage type. For a bucket, the value is alwaysobject-storage.mount-point: Mount point. The directory with the mounted bucket will be accessible at/function/storage/<mount_point>.bucket: Bucket name.prefix: Bucket folder that will be mounted to the function. Skip this field or leave it empty to mount the entire bucket.mode: Bucket mount mode,ro(read-only) orrw(read and write).
To mount several buckets to a function at the same time, specify
--mountas many times as you need.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
-
Open the Terraform configuration file and add the
mountssection to the function description:resource "yandex_function" "bucketfunction" { ... mounts { name = "<mount_point>" mode = "<mount_mode>" object_storage { bucket = "<bucket_name>" prefix = "<folder_name>" } } }Where:
-
mounts: Object Storage bucket mount settings:name: Mount point. The directory with the mounted bucket will be accessible at/function/storage/<mount_point>.mode: Bucket mount mode,ro(read-only) orrw(read and write).object_storage: Bucket settings:
To mount several buckets to a function at the same time, specify
mountsas many times as you need.
For more information about
yandex_functionresource properties, see this provider guide. -
-
Apply the changes:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
-
You can check the function version update and its settings using the management console
yc serverless function version get <function_version_ID>
Use the createVersion REST API method for the Function resource or the FunctionService/CreateVersion gRPC API call.