CreateVersion
Creates a version for the specified function.
- TypeScript
- Python
import {
cloudApi,
decodeMessage,
serviceClients,
Session,
waitForOperation,
} from "@yandex-cloud/nodejs-sdk";
const CreateFunctionVersionRequest =
cloudApi.serverless.functions_function_service.CreateFunctionVersionRequest;
const LogLevel_Level = cloudApi.logging.log_entry.LogLevel_Level;
const Mount_Mode = cloudApi.serverless.functions_function.Mount_Mode;
const Version = cloudApi.certificatemanager.certificate.Version;
(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.FunctionServiceClient);
const operation = await client.createVersion(
CreateFunctionVersionRequest.fromPartial({
functionId: "functionId",
runtime: "runtime",
// description: "description",
entrypoint: "entrypoint",
resources: {
// memory: 0
},
executionTimeout: {
// seconds: 0,
// nanos: 0
},
// serviceAccountId: "serviceAccountId",
// package: {
// bucketName: "bucketName",
// objectName: "objectName",
// sha256: "sha256"
// },
// content: Buffer.from([]),
// versionId: "versionId",
// environment: {"key": "environment"},
// tag: ["tag"],
// connectivity: {
// networkId: "networkId",
// subnetId: ["subnetId"]
// },
// namedServiceAccounts: {"key": "namedServiceAccounts"},
// secrets: [{
// id: "id",
// versionId: "versionId",
// key: "key",
// environmentVariable: "environmentVariable"
// }],
// logOptions: {
// disabled: true,
// logGroupId: "logGroupId",
// folderId: "folderId",
// minLevel: LogLevel_Level.TRACE
// },
// storageMounts: [{
// bucketId: "bucketId",
// prefix: "prefix",
// mountPointName: "mountPointName",
// readOnly: true
// }],
// asyncInvocationConfig: {
// retriesCount: 0,
// successTarget: {
// emptyTarget: {
// },
// ymqTarget: {
// queueArn: "queueArn",
// serviceAccountId: "serviceAccountId"
// }
// },
// failureTarget: {
// emptyTarget: {
// },
// ymqTarget: {
// queueArn: "queueArn",
// serviceAccountId: "serviceAccountId"
// }
// },
// serviceAccountId: "serviceAccountId"
// },
// tmpfsSize: 0,
// concurrency: 0,
// mounts: [{
// name: "name",
// mode: Mount_Mode.READ_ONLY,
// objectStorage: {
// bucketId: "bucketId",
// prefix: "prefix"
// },
// ephemeralDiskSpec: {
// size: 0,
// blockSize: 0
// }
// }]
})
);
const finishedOp = await waitForOperation(operation, session);
if (finishedOp.response) {
const result = decodeMessage<typeof Version>(finishedOp.response);
console.log(result);
}
})();
import os
import grpc
import yandexcloud
from yandex.cloud.serverless.functions.v1.function_pb2 import AsyncInvocationConfig
from yandex.cloud.serverless.functions.v1.function_pb2 import Connectivity
from yandex.cloud.serverless.functions.v1.function_service_pb2 import CreateFunctionVersionMetadata
from yandex.cloud.serverless.functions.v1.function_service_pb2 import CreateFunctionVersionRequest
from yandex.cloud.serverless.functions.v1.function_pb2 import EmptyTarget
from yandex.cloud.serverless.functions.v1.function_service_pb2_grpc import FunctionServiceStub
from yandex.cloud.serverless.functions.v1.function_pb2 import LogOptions
from yandex.cloud.serverless.functions.v1.function_pb2 import Mount
from yandex.cloud.serverless.functions.v1.function_pb2 import Package
from yandex.cloud.serverless.functions.v1.function_pb2 import Resources
from yandex.cloud.serverless.functions.v1.function_pb2 import Secret
from yandex.cloud.serverless.functions.v1.function_pb2 import StorageMount
from yandex.cloud.certificatemanager.v1.certificate_pb2 import Version
from yandex.cloud.serverless.functions.v1.function_pb2 import YMQTarget
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(FunctionServiceStub)
operation = service.CreateVersion(
CreateFunctionVersionRequest(
function_id="functionId",
runtime="runtime",
# description = "description",
entrypoint="entrypoint",
resources=Resources(
# memory = 0
),
execution_timeout=Duration(
# seconds = 0,
# nanos = 0
),
# service_account_id = "serviceAccountId",
# package = Package(
# bucket_name = "bucketName",
# object_name = "objectName",
# sha_256 = "sha256"
# ),
# content = b'',
# version_id = "versionId",
# environment = {"key": "environment"},
# tag = ["tag"],
# connectivity = Connectivity(
# network_id = "networkId",
# subnet_id = ["subnetId"]
# ),
# named_service_accounts = {"key": "namedServiceAccounts"},
# secrets = [Secret(
# id = "id",
# version_id = "versionId",
# key = "key",
# environment_variable = "environmentVariable"
# )],
# log_options = LogOptions(
# disabled = true,
# log_group_id = "logGroupId",
# folder_id = "folderId",
# min_level = LogLevel.Level.TRACE
# ),
# storage_mounts = [StorageMount(
# bucket_id = "bucketId",
# prefix = "prefix",
# mount_point_name = "mountPointName",
# read_only = true
# )],
# async_invocation_config = AsyncInvocationConfig(
# retries_count = 0,
# success_target = AsyncInvocationConfig.ResponseTarget(
# empty_target = EmptyTarget(
# ),
# ymq_target = YMQTarget(
# queue_arn = "queueArn",
# service_account_id = "serviceAccountId"
# )
# ),
# failure_target = AsyncInvocationConfig.ResponseTarget(
# empty_target = EmptyTarget(
# ),
# ymq_target = YMQTarget(
# queue_arn = "queueArn",
# service_account_id = "serviceAccountId"
# )
# ),
# service_account_id = "serviceAccountId"
# ),
# tmpfs_size = 0,
# concurrency = 0,
# mounts = [Mount(
# name = "name",
# mode = Mount.Mode.READ_ONLY,
# object_storage = Mount.ObjectStorage(
# bucket_id = "bucketId",
# prefix = "prefix"
# ),
# ephemeral_disk_spec = Mount.DiskSpec(
# size = 0,
# block_size = 0
# )
# )]
)
)
operation_result = sdk.wait_operation_and_get_result(
operation,
response_type=Version,
meta_type=CreateFunctionVersionMetadata,
)
print(operation_result)
CreateFunctionVersionRequest
functionId
: string
ID of the function to create a version for.
To get a function ID, make a FunctionService.List request.
runtime
: string
Runtime environment for the version.
description
: string
Description of the version
entrypoint
: string
Entrypoint of the version.
resources
: Resources
Resources allocated to the version.
executionTimeout
: google.protobuf.Duration
Timeout for the execution of the version.
If the timeout is exceeded, Cloud Functions responds with a 504 HTTP code.
serviceAccountId
: string
ID of the service account to associate with the version.
One of packageSource
Source of the deployment package for the version.
package
: PackageFunctions deployment package.
content
: bytesContent of the deployment package.
versionId
: stringID of the version to be copied from. Source version must belong to the same folder as the created version
and the user must have read permissions to the source version.
environment
: string
Environment settings for the version.
tag
: string
Function version tags. For details, see Version tag.
connectivity
: Connectivity
Function version connectivity. If specified the version will be attached to specified network/subnet(s).
namedServiceAccounts
: string
Additional service accounts to be used by the version.
secrets
: Secret
Yandex Lockbox secrets to be used by the version.
logOptions
: LogOptions
Options for logging from the function
storageMounts
: StorageMount
S3 mounts to be used by the version.
asyncInvocationConfig
: AsyncInvocationConfig
Config for asynchronous invocations of the version
tmpfsSize
: int64
Optional size of in-memory mounted /tmp directory in bytes. Available for versions with resources.memory greater or equal to 1024 MiB.
0 or in range from 512 MiB to 3/4 of resources.memory.
concurrency
: int64
The maximum number of requests processed by a function instance at the same time
mounts
: Mount
Mounts to be used by the version.
Resources
Resources allocated to a version.
memory
: int64
Amount of memory available to the version, specified in bytes, multiple of 128MB.
Package
Version deployment package.
bucketName
: string
Name of the bucket that stores the code for the version.
objectName
: string
Name of the object in the bucket that stores the code for the version.
sha256
: string
SHA256 hash of the version deployment package.
Connectivity
Version connectivity specification.
networkId
: string
Network the version will have access to. It's essential to specify network with subnets in all availability zones.
subnetId
: string
Complete list of subnets (from the same network) the version can be attached to. It's essential to specify at least one subnet for each availability zones.
Secret
Secret for serverless function.
id
: string
ID of Yandex Lockbox secret.
versionId
: string
ID of Yandex Lockbox version.
key
: string
Key in secret's payload, which value to be delivered into function environment.
One of reference
environmentVariable
: stringenvironment variable in which secret's value to be delivered.
LogOptions
disabled
: bool
Is logging from function disabled.
One of destination
Log entries destination.
logGroupId
: stringEntry should be written to log group resolved by ID.
folderId
: stringEntry should be written to default log group for specified folder.
minLevel
: yandex.cloud.logging.v1.LogLevel.Level
Minimum log entry level.
See LogLevel.Level for details.
StorageMount
bucketId
: string
S3 bucket name for mounting.
prefix
: string
S3 bucket prefix for mounting.
mountPointName
: string
Mount point directory name (not path) for mounting.
readOnly
: bool
Is mount read only.
AsyncInvocationConfig
ResponseTarget
Target to which a result of an invocation will be sent
One of target
emptyTarget
: EmptyTargetTarget to ignore a result
ymqTarget
: YMQTargetTarget to send a result to ymq
retriesCount
: int64
Number of retries of version invocation
successTarget
: ResponseTarget
Target for successful result of the version's invocation
failureTarget
: ResponseTarget
Target for unsuccessful result, if all retries failed
serviceAccountId
: string
Service account which can invoke version
Mount
Mount contains an information about version's external storage mount
Mode
MODE_UNSPECIFIED
READ_ONLY
READ_WRITE
ObjectStorage
ObjectStorage as a mount
bucketId
: string
ObjectStorage bucket name for mounting.
prefix
: string
ObjectStorage bucket prefix for mounting.
DiskSpec
Disk as a mount
size
: int64
The size of disk for mount in bytes
blockSize
: int64
Optional block size of disk for mount in bytes
name
: string
Unique mount point name. Device will be mounted into /function/storage/<name>
mode
: Mode
Mount's mode
objectStorage
: ObjectStorageObject storage mounts
ephemeralDiskSpec
: DiskSpecWorking disk (worker-local non-shared read-write NBS disk templates)
EmptyTarget
YMQTarget
queueArn
: string
Queue ARN
serviceAccountId
: string
Service account which has write permission on the queue.
ResponseTarget
Target to which a result of an invocation will be sent
emptyTarget
: EmptyTargetTarget to ignore a result
ymqTarget
: YMQTargetTarget to send a result to ymq
ObjectStorage
ObjectStorage as a mount
bucketId
: string
ObjectStorage bucket name for mounting.
prefix
: string
ObjectStorage bucket prefix for mounting.
DiskSpec
Disk as a mount
size
: int64
The size of disk for mount in bytes
blockSize
: int64
Optional block size of disk for mount in bytes
Operation
An Operation resource. For more information, see Operation.
id
: string
ID of the operation.
description
: string
Description of the operation. 0-256 characters long.
createdAt
: google.protobuf.Timestamp
Creation timestamp.
createdBy
: string
ID of the user or service account who initiated the operation.
modifiedAt
: google.protobuf.Timestamp
The time when the Operation resource was last modified.
done
: bool
If the value is false
, it means the operation is still in progress.
If true
, the operation is completed, and either error
or response
is available.
metadata
: google.protobuf.Any
Service-specific metadata associated with the operation. It typically contains the ID of the target resource that the operation is performed on. Any method that returns a long-running operation should document the metadata type, if any.
One of result
The operation result.
If done == false
and there was no failure detected, neither error
nor response
is set.
If done == false
and there was a failure detected, error
is set.
If done == true
, exactly one of error
or response
is set.
error
: google.rpc.StatusThe error result of the operation in case of failure or cancellation.
response
: google.protobuf.AnyThe normal response of the operation in case of success.
If the original method returns no data on success, such as Delete, the response is google.protobuf.Empty. If the original method is the standard Create/Update, the response should be the target resource of the operation. Any method that returns a long-running operation should document the response type, if any.