Skip to main content

Edge Compute Quick Start

Deploy serverless functions on Telnyx Edge Compute in under 5 minutes.

Tutorial Objectives

This tutorial covers:

  • Deploying a function that responds globally in under 50ms.
  • Learning the basic Edge Compute development workflow.
  • Testing functions from anywhere in the world.
  • Understanding edge computing in practice.

Prerequisites

  • A Telnyx account with API access - Sign up here if needed.
  • Command line familiarity - Requires Terminal (macOS/Linux) or Command Prompt (Windows).
  • Time requirement - This guide takes approximately 5 minutes to complete.

Install the CLI

Download Binary

Download the latest release for the target platform from the GitHub releases page.

Extract the archive and add the binary to your PATH or run directly.

Example for Linux/macOS:

tar -xzf telnyx-edge-linux-amd64.tar.gz
sudo mv telnyx-edge-linux-amd64/telnyx-edge /usr/local/bin/

Authenticate

Authenticate with a Telnyx API key:

telnyx-edge auth api-key set YOUR_API_KEY

Verify authentication:

telnyx-edge auth status

Create a Function

Create a simple "Hello World" function:

telnyx-edge new-func --language=go --name=hello-world

This creates a new directory with the function:

hello-world/
├── main.go # Your function code
├── go.mod # Go dependencies
└── func.toml # Function configuration

Function Code

The generated main.go contains a basic HTTP handler:

package main

import (
"encoding/json"
"fmt"
"net/http"
"os"
)

type Response struct {
Message string `json:"message"`
Status string `json:"status"`
}

func handler(w http.ResponseWriter, r *http.Request) {
response := Response{
Message: "Hello from Telnyx Edge Compute!",
Status: "success",
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}

func main() {
http.HandleFunc("/", handler)

port := os.Getenv("PORT")
if port == "" {
port = "8080"
}

fmt.Printf("Server starting on port %s\n", port)
http.ListenAndServe(":"+port, nil)
}

Deploy the Function

Navigate to the function directory and deploy:

cd hello-world
telnyx-edge deploy

The CLI will:

  1. Validate your function structure.
  2. Check authentication.
  3. Package your function files.
  4. Upload to Telnyx Edge infrastructure.
  5. Deploy across edge locations.

You'll see output like:

Deploying function 'hello-world'...
✓ Function validated successfully
✓ Authentication verified
✓ Files packaged (2.3 KB)
✓ Uploaded to edge infrastructure
✓ Deployed to 12 edge locations

Function URL: https://hello-world-abc123.edge.telnyx.com
Deployment ID: dep_abc123xyz789
Status: Active

Test the Function

Test the deployed function:

curl https://hello-world-abc123.edge.telnyx.com

Response:

{
"message": "Hello from Telnyx Edge Compute!",
"status": "success"
}

Success! The Function is Live

The function is now running globally and should respond in under 100ms from anywhere in the world. The URL https://hello-world-abc123.edge.telnyx.com is accessible worldwide.

Building on the Basics

Common implementation patterns include:

Handle Different HTTP Methods

func handler(w http.ResponseWriter, r *http.Request) {
var response Response

switch r.Method {
case "GET":
response = Response{Message: "Hello from GET request!", Status: "success"}
case "POST":
response = Response{Message: "Data received via POST!", Status: "success"}
default:
response = Response{Message: "Method not supported", Status: "error"}
w.WriteHeader(http.StatusMethodNotAllowed)
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}

Use Environment Variables

func handler(w http.ResponseWriter, r *http.Request) {
greeting := os.Getenv("GREETING")
if greeting == "" {
greeting = "Hello"
}

response := Response{
Message: fmt.Sprintf("%s from Telnyx Edge Compute!", greeting),
Status: "success",
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}

Parse Query Parameters

func handler(w http.ResponseWriter, r *http.Request) {
name := r.URL.Query().Get("name")
if name == "" {
name = "World"
}

response := Response{
Message: fmt.Sprintf("Hello %s from Telnyx Edge Compute!", name),
Status: "success",
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}

Next Steps

The edge function has been successfully deployed. Explore these topics next:

Explore More Languages

Try creating functions in different languages:

# JavaScript/Node.js
telnyx-edge new-func --language=js --name=my-js-function

# Python
telnyx-edge new-func --language=python --name=my-python-function

# TypeScript
telnyx-edge new-func --language=ts --name=my-ts-function

Learn Core Concepts

Integrate with Telnyx Services

Common Commands

Here are the most frequently used CLI commands:

# Authentication
telnyx-edge auth login # Login with OAuth.
telnyx-edge auth status # Check auth status.
telnyx-edge auth logout # Logout.

# Function management
telnyx-edge new-func -l=go -n=my-func # Create new function.
telnyx-edge deploy # Deploy current function.
telnyx-edge list # List all functions.
telnyx-edge logs -n=my-func # View function logs.

# Secrets management
telnyx-edge secrets add API_KEY "value" # Add a secret.
telnyx-edge secrets list # List secrets.
telnyx-edge secrets delete API_KEY # Delete a secret.

# System
telnyx-edge status # Check CLI status.
telnyx-edge help # Show help.

Getting Help

Need help? Here are your options: