Creating a function
-
In the management console
, select the folder where you want to create a function. -
Select Cloud Functions.
-
Click Create function.
-
Enter a name and description for the function. The name format is as follows:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
-
Click Create.
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 create a function, run the command:
yc serverless function create --name=<function_name>
Result:
id: b09bhaokchn9********
folder_id: aoek49ghmknn********
created_at: "2019-06-14T10:03:37.475Z"
name: python_function
log_group_id: eolm8aoq9vcp********
http_invoke_url: https://functions.yandexcloud.net/b09bhaokchn9********
status: ACTIVE
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To create a function:
-
In the configuration file, describe the parameters of the resources you want to create:
yandex_function
: Description of the function being created and its source code:name
: Function name.folder_id
: Folder ID.description
: Text description of the function.labels
: Function labels inkey:value
format.user_hash
: Arbitrary string that identifies the function version. When the function changes, update this string, too. The function will update when this string is updated.runtime
: Function runtime environment.entrypoint
: Function name in the source code that will serve as an entry point to the applications.memory
: Amount of memory allocated for function execution, in MB.execution_timeout
: Function execution timeout.service_account_id
: ID of the service account to invoke the function under.environment
: Environment variables inkey:value
format.tags
: Function tags.version
: Function version.image_size
: Size of the image for the function.loggroup_id
: ID of the log group for the function.package
: Package with the source code of the function version. You can only use either thepackage
orcontent
field.package.0.sha_256
: SHA256 hash of the deployed package.package.0.bucket_name
: Name of the bucket in Object Storage that stores the source code of the function version.package.0.object_name
: Name of the object in Object Storage that contains the source code of the function version.content
: Function source code. You can only use either thecontent
orpackage
field.content.0.zip_filename
: Name of the ZIP archive that contains the function source code.
Here is an example of the configuration file structure:
provider "yandex" { token = "<service_account_OAuth_token_or_static_key>" folder_id = "<folder_ID>" zone = "ru-central1-a" } resource "yandex_function" "test-function" { name = "test-function" description = "Test function" user_hash = "first-function" runtime = "python37" entrypoint = "main" memory = "128" execution_timeout = "10" service_account_id = "<service_account_ID>" tags = ["my_tag"] content { zip_filename = "<ZIP_archive_path>" } } output "yandex_function_test-function" { value = "${yandex_function.test-function.id}" }
For more information about the
yandex_function
resource parameters, see the provider documentation . -
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.You can check the new resources and their configuration using the management console
or this CLI command:yc serverless function list
To create a function, use the create REST API method for the Function resource or the FunctionService/Create gRPC API call.
You can create a function using the Yandex Cloud Toolkit plugin