Modificar Lambda

Actualiza campos soportados de una lambda existente.

Autenticación

Requiere X-Glue-Authentication.

Parámetros de Path

Parámetro Tipo Descripción
lambda_id string Identificador de la lambda

Cuerpo de la Solicitud

Campo Tipo Descripción
name string Nuevo nombre de la lambda
language string javascript, static-html, static-css o static-js
code string Nuevo código fuente o contenido estático
method string Nuevo método HTTP
path string Nuevo path HTTP

Solicitud HTTP

curl -X PATCH "https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789" \
  -H "X-Glue-Authentication: TU_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "hello-updated",
  "method": "POST",
  "path": "/hello-updated",
  "code": "export default (req) => ({ body: { message: '\''Updated lambda'\'', data: req.body } })"
}'
PATCH /api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789 HTTP/1.1
Host: api.hola.cloud
X-Glue-Authentication: TU_TOKEN
Content-Type: application/json

{
  "name": "hello-updated",
  "method": "POST",
  "path": "/hello-updated",
  "code": "export default (req) => ({ body: { message: 'Updated lambda', data: req.body } })"
}
package main

import (
	"fmt"
	"io"
	"net/http"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"code": "export default (req) => ({ body: { message: 'Updated lambda', data: req.body } })", "method": "POST", "name": "hello-updated", "path": "/hello-updated"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("PATCH", "https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("X-Glue-Authentication", "TU_TOKEN")
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['code' => 'export default (req) => ({ body: { message: \'Updated lambda\', data: req.body } })', 'method' => 'POST', 'name' => 'hello-updated', 'path' => '/hello-updated'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'PATCH',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'X-Glue-Authentication: TU_TOKEN',
        'Content-Type: application/json',
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import requests

import json

headers = {
    "X-Glue-Authentication": "TU_TOKEN",
    "Content-Type": "application/json",
}

payload = {"code": "export default (req) => ({ body: { message: 'Updated lambda', data: req.body } })", "method": "POST", "name": "hello-updated", "path": "/hello-updated"}
body = json.dumps(payload)

response = requests.request(
    "PATCH",
    "https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"code": "export default (req) => ({ body: { message: 'Updated lambda', data: req.body } })", "method": "POST", "name": "hello-updated", "path": "/hello-updated"};

const response = await fetch("https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789", {
  method: "PATCH",
  headers: {
    "X-Glue-Authentication": "TU_TOKEN",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
const payload = {"code": "export default (req) => ({ body: { message: 'Updated lambda', data: req.body } })", "method": "POST", "name": "hello-updated", "path": "/hello-updated"};

const response = await fetch("https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789", {
  method: "PATCH",
  headers: {
    "X-Glue-Authentication": "TU_TOKEN",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("code", "export default (req) => ({ body: { message: 'Updated lambda', data: req.body } })", "method", "POST", "name", "hello-updated", "path", "/hello-updated");
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789"))
            .method("PATCH", HttpRequest.BodyPublishers.ofString(body))
            .header("X-Glue-Authentication", "TU_TOKEN")
            .header("Content-Type", "application/json")
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

Ejemplo

curl -X PATCH "https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789" \
  -H "X-Glue-Authentication: TU_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "hello-updated",
    "method": "POST",
    "path": "/hello-updated",
    "code": "export default (req) => ({ body: { message: \"Updated lambda\", data: req.body } })"
  }'
PATCH /api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789 HTTP/1.1
Host: api.hola.cloud
X-Glue-Authentication: TU_TOKEN
Content-Type: application/json

{
    "name": "hello-updated",
    "method": "POST",
    "path": "/hello-updated",
    "code": "export default (req) => ({ body: { message: \"Updated lambda\", data: req.body } })"
  }
package main

import (
	"fmt"
	"io"
	"net/http"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"code": "export default (req) => ({ body: { message: \"Updated lambda\", data: req.body } })", "method": "POST", "name": "hello-updated", "path": "/hello-updated"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("PATCH", "https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("X-Glue-Authentication", "TU_TOKEN")
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['code' => 'export default (req) => ({ body: { message: "Updated lambda", data: req.body } })', 'method' => 'POST', 'name' => 'hello-updated', 'path' => '/hello-updated'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'PATCH',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'X-Glue-Authentication: TU_TOKEN',
        'Content-Type: application/json',
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import requests

import json

headers = {
    "X-Glue-Authentication": "TU_TOKEN",
    "Content-Type": "application/json",
}

payload = {"code": "export default (req) => ({ body: { message: \"Updated lambda\", data: req.body } })", "method": "POST", "name": "hello-updated", "path": "/hello-updated"}
body = json.dumps(payload)

response = requests.request(
    "PATCH",
    "https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"code": "export default (req) => ({ body: { message: \"Updated lambda\", data: req.body } })", "method": "POST", "name": "hello-updated", "path": "/hello-updated"};

const response = await fetch("https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789", {
  method: "PATCH",
  headers: {
    "X-Glue-Authentication": "TU_TOKEN",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
const payload = {"code": "export default (req) => ({ body: { message: \"Updated lambda\", data: req.body } })", "method": "POST", "name": "hello-updated", "path": "/hello-updated"};

const response = await fetch("https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789", {
  method: "PATCH",
  headers: {
    "X-Glue-Authentication": "TU_TOKEN",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("code", "export default (req) => ({ body: { message: \"Updated lambda\", data: req.body } })", "method", "POST", "name", "hello-updated", "path", "/hello-updated");
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/api/v0/lambdas/f1a2b3c4-d5e6-7890-abcd-ef0123456789"))
            .method("PATCH", HttpRequest.BodyPublishers.ofString(body))
            .header("X-Glue-Authentication", "TU_TOKEN")
            .header("Content-Type", "application/json")
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

Respuesta

 1{
 2  "id": "f1a2b3c4-d5e6-7890-abcd-ef0123456789",
 3  "created_timestamp": 1751378400,
 4  "owner": "user_123",
 5  "project_id": "project_456",
 6  "name": "hello-updated",
 7  "language": "javascript",
 8  "code": "export default (req) => ({ body: { message: \"Updated lambda\", data: req.body } })",
 9  "method": "POST",
10  "path": "/hello-updated"
11}

Códigos de Error

Código Descripción
400 Cuerpo de solicitud inválido
401 Autenticación faltante o inválida
404 Lambda no encontrada

Comentarios

Deja un comentario