PandaEdge

Edge Functions User Guide

Edge Functions allow you to run custom code at the edge of the network, closer to your users for faster response times. This guide will help you understand how to create, deploy, and manage your edge functions effectively.

Table of Contents

Creating a Function

Using the UI

  1. Navigate to the Edge Functions section in your dashboard

  2. Click the "Create Function" button

  3. Fill in the basic information:

    • Function Name: Choose a unique name (4-12 characters, lowercase letters, numbers, and hyphens only)

    • Runtime: Select your preferred programming language and version

  4. Write your code or upload a zip file containing your function files

  5. Configure memory, timeout, and environment variables

  6. Click "Deploy" to create your function

Function Naming

  • Names must be 4-12 characters long

  • Only lowercase letters, numbers, and hyphens are allowed

  • A random 6-character suffix will be added to your function name during deployment

Supported Runtimes

Our platform supports multiple programming languages:

Runtime
Versions
Main File

Node.js

14, 16, 18, 20

index.js

Python

3, 3.9

main.py

Java

8

Main.java

Swift

5.1

main.swift

PHP

7.4

index.php

Ruby

2.5

main.rb

Go

1.15

main.go

Rust

1.54

main.rs

.NET

3.1

Main.cs

Ballerina

0.990

main.bal

Function Structure

Each function must have a main handler that processes incoming requests. The structure varies slightly depending on the programming language.

Node.js Example

Python Example

Environment Variables & Parameters

Setting Environment Variables

You can set environment variables in two ways:

  1. Through the UI: When creating or editing a function, use the Environment Variables section

  2. During deployment: Add them to your request when using the API

Environment variables are passed to your function through the params object.

Using Parameters

Parameters are passed to your function through the params object. There are multiple ways to pass parameters:

  1. Query parameters: These are automatically included in the params object

  2. JSON body: For POST requests, the JSON body is merged into the params object

  3. Environment variables: All environment variables are included in the params object

Example: Accessing Parameters

Function Limits

Our platform enforces the following limits for edge functions:

Resource
Default
Min
Max

Memory

256 MB

128 MB

1024 MB

Timeout

30 seconds

1 second

300 seconds

Package Size

-

-

10 MB

Concurrent Executions

1

-

-

Log Size

-

-

10 MB

Deploying Functions

Using the UI

  1. Complete the function creation form

  2. Click "Deploy" to create and activate your function

Function URL

After deployment, your function will be accessible at:

Testing Functions

Using the UI

  1. Navigate to your function's details page

  2. Go to the "Testing" tab

  3. Enter test parameters in JSON format

  4. Click "Test Function" to see the result

Using cURL

You can test your function using cURL:

Monitoring & Logs

Viewing Logs

  1. Navigate to your function's details page

  2. Go to the "Logs" tab to see execution logs

  3. Use console.log() (Node.js) or print() (Python) to add custom log entries

Monitoring Metrics

The "Monitoring" tab provides metrics such as:

  • Invocation count

  • Error rate

  • Execution duration

  • Memory usage

Examples

Example 1: Simple API Response

Example 2: Using Environment Variables for Authentication

Example 3: Processing Form Data (Node.js)

Example 4: Handling Different HTTP Methods

Example 5: External API Integration (Python)

Example 6: Accessing OpenWhisk System Information

Your function has access to special parameters that provide information about the OpenWhisk environment:

Troubleshooting

Common Issues

  1. Function Returns 502 Bad Gateway

    • Ensure your function returns a proper response object

    • Check your function logs for errors

    • Verify your function isn't timing out

  2. Environment Variables Not Working

    • Make sure they are correctly set in the UI

    • Verify you're accessing them via the params object

  3. Function Takes Too Long to Execute

    • Check if your function is making slow external API calls

    • Consider increasing the memory allocation

    • Optimize your code for better performance

Getting Help

If you continue to experience issues, please contact our support team with:

  • Your function name

  • Any error messages

  • Steps to reproduce the issue

  • Relevant logs


For more information or technical support, please contact our support team at [email protected]

Last updated