### List Yandex Cloud Functions with yc-cli Source: https://github.com/sourcecraft/yc-cloud-functions-template.git/blob/main/README.md This example shows how to list Yandex Cloud Functions using the 'yc-cli' cube. It utilizes IAM token and folder ID from previous steps or configurations to authenticate and interact with the Yandex Cloud API. ```yaml - name: get-functions env: YC_IAM_TOKEN: "${{ cubes.get-iam-token.outputs.IAM_TOKEN }}" YC_FOLDER_ID: "${{ tokens.my-token.folder_id }}" image: name: cr.yandex/sourcecraft/yc-cli:latest entrypoint: "" script: - | yc config set folder-id $YC_FOLDER_ID yc serverless function list ``` -------------------------------- ### Deploy Yandex Cloud Function with yc-function Source: https://github.com/sourcecraft/yc-cloud-functions-template.git/blob/main/README.md This snippet demonstrates deploying a Yandex Cloud Function using the 'yc-function' cube. It requires essential parameters like function name, runtime, and entrypoint. Optional parameters include source path, environment variables, and public accessibility. ```yaml - name: deploy-yc-function env: YC_FUNCTION_NAME: "my-function" YC_FUNCTION_RUNTIME: "python311" YC_FUNCTION_ENTRYPOINT: "handler.main" SOURCE_PATH: "./src" PUBLIC: "true" image: name: cr.yandex/sourcecraft/yc-function:latest entrypoint: "" script: - | # Deployment script using yc-function cube echo "Deploying function..." ``` -------------------------------- ### YC CLI for Complex Scenarios Source: https://context7.com/sourcecraft/yc-cloud-functions-template.git/llms.txt An example of using Yandex Cloud CLI within a cube for advanced deployment scenarios, including setting up environment variables and listing serverless functions. This requires IAM token and folder ID. ```yaml # Пример использования yc-cli для получения списка функций - name: get-functions env: YC_IAM_TOKEN: ${{ cubes.<имя_кубика_с_IAM-токеном>.outputs.IAM_TOKEN }} YC_FOLDER_ID: ${{ tokens.<имя_токена>.folder_id }} image: name: cr.yandex/sourcecraft/yc-cli:latest entrypoint: "" script: - | yc config set folder-id $YC_FOLDER_ID yc serverless function list # Обязательные переменные окружения для yc-function: # YC_FUNCTION_NAME - имя функции (уникальное в каталоге) # YC_FUNCTION_RUNTIME - идентификатор среды выполнения # YC_FUNCTION_ENTRYPOINT - точка входа функции # Дополнительные параметры: # SOURCE_PATH - папка с исходным кодом (по умолчанию "./src") # ENVIRONMENT - переменные окружения функции # PUBLIC - сделать функцию публично доступной ``` -------------------------------- ### Go Yandex Cloud Function Handler Source: https://context7.com/sourcecraft/yc-cloud-functions-template.git/llms.txt A Go handler for Yandex Cloud Functions using typed Request and Response structures. It leverages the `context` package for request processing and returns a structured JSON response. This example showcases Go's strong typing for serverless function development. ```go // go/index.go package main import ( "context" ) type Response struct { StatusCode int `json:"statusCode"` Body interface{} `json:"body"` } func Handler(ctx context.Context) (*Response, error) { return &Response{ StatusCode: 200, Body: "Hello, world!", }, nil } // Конфигурация для развертывания: // YC_FUNCTION_RUNTIME: "golang123" // YC_FUNCTION_ENTRYPOINT: "index.Handler" ``` -------------------------------- ### Node.js Yandex Cloud Function Handler Source: https://context7.com/sourcecraft/yc-cloud-functions-template.git/llms.txt An asynchronous Node.js handler for Yandex Cloud Functions. It processes incoming events, including query parameters and POST request bodies, returning a JSON response with appropriate HTTP headers. This example demonstrates basic event handling and response formatting. ```javascript // nodejs/index.js export const handler = async function (event, context) { // Log the incoming event for debugging console.log('Received event:', event); // Access request body (if it's a POST request) const requestBody = event.body ? JSON.parse(event.body) : {}; // Access query parameters const name = event.queryStringParameters ? event.queryStringParameters.name : 'World'; return { statusCode: 200, headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ message: `Hello, ${name}! Your request body was:`, data: requestBody, }), }; }; // Пример вызова функции через curl: // curl "https://functions.yandexcloud.net/?name=Разработчик" // Ожидаемый ответ: // {"message":"Hello, Разработчик! Your request body was:","data":{}} ``` -------------------------------- ### Configure CI/CD Workflow with SourceCraft Source: https://context7.com/sourcecraft/yc-cloud-functions-template.git/llms.txt This YAML configuration defines the CI/CD workflow for deploying Node.js functions to Yandex Cloud. It specifies push triggers, service connection tokens, and deployment parameters including function name, runtime, and entrypoint. ```yaml # .sourcecraft/ci.yaml on: push: - workflows: [deploy-nodejs-function] filter: branches: ["master", "main"] tokens: SERVICE_CONNECTION_WITH_TOKEN: service_connection: "default-service-connection" scope: org workflows: deploy-nodejs-function: tasks: - name: deploy-nodejs-function-task cubes: - name: test-yc-func-image-nodejs env: ID_TOKEN: ${{ tokens.SERVICE_CONNECTION_WITH_TOKEN.id_token }} YC_SA_ID: ${{ tokens.SERVICE_CONNECTION_WITH_TOKEN.service_account_id }} YC_FOLDER_ID: ${{ tokens.SERVICE_CONNECTION_WITH_TOKEN.folder_id }} YC_FUNCTION_NAME: "test-function-nodejs" YC_FUNCTION_RUNTIME: "nodejs22" YC_FUNCTION_ENTRYPOINT: "index.handler" SOURCE_PATH: "./nodejs" image: cr.yandex/sourcecraft/yc-function:latest ``` -------------------------------- ### Kotlin Cloud Function Handler Source: https://context7.com/sourcecraft/yc-cloud-functions-template.git/llms.txt A Kotlin handler utilizing data classes for Request and Response, offering a concise syntax for serverless request handling. Deployment requires YC_FUNCTION_RUNTIME set to 'kotlin20' and YC_FUNCTION_ENTRYPOINT to 'Handler'. ```kotlin data class Request( val httpMethod: String?, val headers: Map = mapOf(), val body: String = "" ) data class Response( val statusCode: Int, val body: String ) fun handle(request: Request): Response { return Response(200, "Hello World!") } // Конфигурация для развертывания: // YC_FUNCTION_RUNTIME: "kotlin20" // YC_FUNCTION_ENTRYPOINT: "Handler" ``` -------------------------------- ### Bash Cloud Function Handler Source: https://context7.com/sourcecraft/yc-cloud-functions-template.git/llms.txt A Bash shell script handler that uses `jq` to format JSON responses, suitable for simple automation and integration tasks. Deployment requires YC_FUNCTION_RUNTIME set to 'bash-2204' and YC_FUNCTION_ENTRYPOINT to 'handler.sh'. ```bash #!/bin/bash # bash/handler.sh RESPONSE=$(echo '{"statusCode":200, "body":"Hello, World!"}' | jq '.') echo $RESPONSE | jq -c '.body |= tostring' # Конфигурация для развертывания: # YC_FUNCTION_RUNTIME: "bash-2204" # YC_FUNCTION_ENTRYPOINT: "handler.sh" ``` -------------------------------- ### .NET Cloud Function Handler Source: https://context7.com/sourcecraft/yc-cloud-functions-template.git/llms.txt A C# handler for the .NET runtime, using typed Request and Response classes within the Function namespace. Deployment requires YC_FUNCTION_RUNTIME set to 'dotnet8' and YC_FUNCTION_ENTRYPOINT to 'Function.Handler'. ```csharp // dotnet/Function.cs using System; namespace Function; public class Request { public string httpMethod { get; set; } public string body { get; set; } } public class Response { public Response(int statusCode, string body) { StatusCode = statusCode; Body = body; } public int StatusCode { get; set; } public string Body { get; set; } } public class Handler { public Response FunctionHandler(Request request) { return new Response(200, "Hello, world!"); } } // Конфигурация для развертывания: // YC_FUNCTION_RUNTIME: "dotnet8" // YC_FUNCTION_ENTRYPOINT: "Function.Handler" ``` -------------------------------- ### PHP Cloud Function Handler Source: https://context7.com/sourcecraft/yc-cloud-functions-template.git/llms.txt A minimalist PHP handler that returns an associative array containing the status code and response body. Deployment requires YC_FUNCTION_RUNTIME set to 'php82' and YC_FUNCTION_ENTRYPOINT to 'index.handler'. ```php 200, "body" => "Hello, World!", ]; } // Конфигурация для развертывания: // YC_FUNCTION_RUNTIME: "php82" // YC_FUNCTION_ENTRYPOINT: "index.handler" ``` -------------------------------- ### R Cloud Function Handler Source: https://context7.com/sourcecraft/yc-cloud-functions-template.git/llms.txt An R language handler designed for statistical computing and analytical tasks, returning a list with a status code and response body. Deployment requires YC_FUNCTION_RUNTIME set to 'r43' and YC_FUNCTION_ENTRYPOINT to 'index.handler'. ```r # r/index.r handler <- function(event, context) { return(list(statusCode = 200, body = "Hello, world!")) } # Конфигурация для развертывания: # YC_FUNCTION_RUNTIME: "r43" # YC_FUNCTION_ENTRYPOINT: "index.handler" ``` -------------------------------- ### Python Yandex Cloud Function Handler Source: https://context7.com/sourcecraft/yc-cloud-functions-template.git/llms.txt A Python handler for Yandex Cloud Functions that processes query parameters and returns a JSON response. It utilizes the standard `json` module for serialization and provides a simple greeting message. This handler is suitable for basic API endpoints. ```python # python/main.py import json def handler(event, context): """ This function processes an incoming request and returns a greeting. """ name = "World" if 'queryStringParameters' in event and 'name' in event['queryStringParameters']: name = event['queryStringParameters']['name'] response_body = { "message": f"Hello, {name}!" } return { 'statusCode': 200, 'headers': { 'Content-Type': 'application/json' }, 'body': json.dumps(response_body) } # Пример вызова: # curl "https://functions.yandexcloud.net/?name=Мир" # Ожидаемый ответ: {"message": "Hello, Мир!"} ``` -------------------------------- ### Java Cloud Function Handler Source: https://context7.com/sourcecraft/yc-cloud-functions-template.git/llms.txt A Java handler implementing the Function interface for typed HTTP request processing using Request and Response classes. Requires YC_FUNCTION_RUNTIME set to 'java21' and YC_FUNCTION_ENTRYPOINT to 'Handler'. ```java import java.util.Map; import java.util.function.Function; class Request { private String httpMethod; private Map headers; } class Response { private int statusCode; private String body; public Response(int statusCode, String body) { this.statusCode = statusCode; this.body = body; } } public class Handler implements Function { @Override public Response apply(Request request) { return new Response(200, "Hello, world!"); } } // Конфигурация для развертывания: // YC_FUNCTION_RUNTIME: "java21" // YC_FUNCTION_ENTRYPOINT: "Handler" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.