Managing Lambda Functions

After creating a lambda, use the management API to inspect it, update its supported fields, list all lambdas in the account, or delete it.

Function Structure

JavaScript lambdas export a default handler. The handler receives a request object and returns the response body you want HolaCloud to send back.

 1export default (req) => {
 2  return {
 3    body: {
 4      method: req.method,
 5      path: req.path,
 6      headers: req.headers,
 7      data: req.body
 8    }
 9  };
10};

Static lambdas use one of the static language modes: static-html, static-css, or static-js. In those modes, code is the content served for the matching lambda.

Updating a Lambda

Use PATCH /api/v0/lambdas/{lambda_id} to update name, language, code, method, or path.

curl -X PATCH "https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID" \
  -H "X-Glue-Authentication: YOUR_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/YOUR_LAMBDA_ID HTTP/1.1
Host: api.hola.cloud
X-Glue-Authentication: YOUR_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/YOUR_LAMBDA_ID", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("X-Glue-Authentication", "YOUR_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/YOUR_LAMBDA_ID',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'PATCH',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'X-Glue-Authentication: YOUR_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": "YOUR_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/YOUR_LAMBDA_ID",
    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/YOUR_LAMBDA_ID", {
  method: "PATCH",
  headers: {
    "X-Glue-Authentication": "YOUR_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/YOUR_LAMBDA_ID", {
  method: "PATCH",
  headers: {
    "X-Glue-Authentication": "YOUR_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/YOUR_LAMBDA_ID"))
            .method("PATCH", HttpRequest.BodyPublishers.ofString(body))
            .header("X-Glue-Authentication", "YOUR_TOKEN")
            .header("Content-Type", "application/json")
            .build();

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

Expected response:

 1{
 2  "id": "f3b2c1a0-1234-5678-9abc-def012345678",
 3  "created_timestamp": 1750507200,
 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}

Viewing Lambda Details

Retrieve one lambda by ID:

curl "https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID" \
  -H "X-Glue-Authentication: YOUR_TOKEN"
GET /api/v0/lambdas/YOUR_LAMBDA_ID HTTP/1.1
Host: api.hola.cloud
X-Glue-Authentication: YOUR_TOKEN
package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	req, err := http.NewRequest("GET", "https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID", nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("X-Glue-Authentication", "YOUR_TOKEN")

	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
$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPHEADER => [
        'X-Glue-Authentication: YOUR_TOKEN',
    ],
]);

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

echo $response;
import requests

headers = {
    "X-Glue-Authentication": "YOUR_TOKEN",
}

response = requests.request(
    "GET",
    "https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID",
    headers=headers
)

print(response.text)
const response = await fetch("https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID", {
  method: "GET",
  headers: {
    "X-Glue-Authentication": "YOUR_TOKEN"
  }
});

console.log(await response.text());
const response = await fetch("https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID", {
  method: "GET",
  headers: {
    "X-Glue-Authentication": "YOUR_TOKEN"
  }
});

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;

public class Main {
    public static void main(String[] args) throws Exception {
        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID"))
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .header("X-Glue-Authentication", "YOUR_TOKEN")
            .build();

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

Listing All Lambdas

curl "https://api.hola.cloud/api/v0/lambdas" \
  -H "X-Glue-Authentication: YOUR_TOKEN"
GET /api/v0/lambdas HTTP/1.1
Host: api.hola.cloud
X-Glue-Authentication: YOUR_TOKEN
package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	req, err := http.NewRequest("GET", "https://api.hola.cloud/api/v0/lambdas", nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("X-Glue-Authentication", "YOUR_TOKEN")

	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
$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/api/v0/lambdas',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPHEADER => [
        'X-Glue-Authentication: YOUR_TOKEN',
    ],
]);

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

echo $response;
import requests

headers = {
    "X-Glue-Authentication": "YOUR_TOKEN",
}

response = requests.request(
    "GET",
    "https://api.hola.cloud/api/v0/lambdas",
    headers=headers
)

print(response.text)
const response = await fetch("https://api.hola.cloud/api/v0/lambdas", {
  method: "GET",
  headers: {
    "X-Glue-Authentication": "YOUR_TOKEN"
  }
});

console.log(await response.text());
const response = await fetch("https://api.hola.cloud/api/v0/lambdas", {
  method: "GET",
  headers: {
    "X-Glue-Authentication": "YOUR_TOKEN"
  }
});

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;

public class Main {
    public static void main(String[] args) throws Exception {
        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/api/v0/lambdas"))
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .header("X-Glue-Authentication", "YOUR_TOKEN")
            .build();

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

Deleting a Lambda

Permanently remove a lambda:

curl -X DELETE "https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID" \
  -H "X-Glue-Authentication: YOUR_TOKEN"
DELETE /api/v0/lambdas/YOUR_LAMBDA_ID HTTP/1.1
Host: api.hola.cloud
X-Glue-Authentication: YOUR_TOKEN
package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	req, err := http.NewRequest("DELETE", "https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID", nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("X-Glue-Authentication", "YOUR_TOKEN")

	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
$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'DELETE',
    CURLOPT_HTTPHEADER => [
        'X-Glue-Authentication: YOUR_TOKEN',
    ],
]);

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

echo $response;
import requests

headers = {
    "X-Glue-Authentication": "YOUR_TOKEN",
}

response = requests.request(
    "DELETE",
    "https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID",
    headers=headers
)

print(response.text)
const response = await fetch("https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID", {
  method: "DELETE",
  headers: {
    "X-Glue-Authentication": "YOUR_TOKEN"
  }
});

console.log(await response.text());
const response = await fetch("https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID", {
  method: "DELETE",
  headers: {
    "X-Glue-Authentication": "YOUR_TOKEN"
  }
});

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;

public class Main {
    public static void main(String[] args) throws Exception {
        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/api/v0/lambdas/YOUR_LAMBDA_ID"))
            .method("DELETE", HttpRequest.BodyPublishers.noBody())
            .header("X-Glue-Authentication", "YOUR_TOKEN")
            .build();

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

A successful deletion returns the API response for the deleted lambda or a confirmation payload, depending on the deployed API version.

Comments

Leave a comment