Skip to main content

CreateVersion

Creates a version for the specified function.

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);
}
})();

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 : Package

    Functions deployment package.

  • content : bytes

    Content of the deployment package.

  • versionId : string
    ID 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 : string

    environment variable in which secret's value to be delivered.

LogOptions

disabled : bool

Is logging from function disabled.

One of destination

Log entries destination.

  • logGroupId : string

    Entry should be written to log group resolved by ID.

  • folderId : string

    Entry 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 : EmptyTarget

    Target to ignore a result

  • ymqTarget : YMQTarget

    Target 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 : ObjectStorage

    Object storage mounts

  • ephemeralDiskSpec : DiskSpec

    Working 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 : EmptyTarget

    Target to ignore a result

  • ymqTarget : YMQTarget

    Target 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.Status

    The error result of the operation in case of failure or cancellation.

  • response : google.protobuf.Any
    The 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.