Skip to main content
Develop and test your Edge Compute functions on your local machine before deploying to Telnyx infrastructure. Run your function code locally using your language’s native tools, then deploy with telnyx-edge ship.

Development Workflow

The local development workflow:
  1. Create function with telnyx-edge new-func
  2. Develop locally using native language tools
  3. Test with your language’s test framework
  4. Deploy with telnyx-edge ship

Quick Start

Create a new function and start developing:
# Create a new function
telnyx-edge new-func -l=python -n=my-function
cd my-function

Running Locally by Language

The scaffolded Go function uses the function package. To test locally, create a test harness:
// handler_test.go
package function

import (
    "net/http"
    "net/http/httptest"
    "testing"
)

func TestHandle(t *testing.T) {
    req := httptest.NewRequest("GET", "/", nil)
    rec := httptest.NewRecorder()

    Handle(rec, req)

    if rec.Code != 200 {
        t.Errorf("Expected status 200, got %d", rec.Code)
    }
}
Run tests:
go test ./...
For local HTTP testing, you can create a temporary main.go:
// +build ignore

package main

import (
    "net/http"

    "example.com/hello-world/function"
)

func main() {
    http.HandleFunc("/", function.Handle)
    http.ListenAndServe(":8080", nil)
}
Run with:
go run main.go

Environment Variables

During local development, set environment variables in your shell or a .env file:
# Option 1: Export in shell
export LOG_LEVEL=debug
export API_URL=https://api.example.com

# Option 2: Use a .env file
echo 'LOG_LEVEL=debug' >> .env
echo 'API_URL=https://api.example.com' >> .env
// Install godotenv
// go get github.com/joho/godotenv

import (
    "os"
    "github.com/joho/godotenv"
)

func init() {
    godotenv.Load() // Load .env file
}

func getLogLevel() string {
    return os.Getenv("LOG_LEVEL")
}
Add .env to your .gitignore to avoid committing local values.

Secrets in Local Development

For local development, mock secrets with environment variables:
# Set secrets locally
export MY_API_KEY="test-key-12345"
export DATABASE_URL="postgres://localhost:5432/devdb"
Your code accesses them the same way it would in production:
import os
api_key = os.getenv("MY_API_KEY")
Never commit actual secret values. Use test/mock values locally and set real secrets with telnyx-edge secrets add for production.

Testing Requests

Once your local server is running, test with curl:
curl http://localhost:8080/

Unit Testing

Write unit tests using your language’s test framework:
// handler_test.go
package function

import (
    "net/http"
    "net/http/httptest"
    "strings"
    "testing"
)

func TestHandleGET(t *testing.T) {
    req := httptest.NewRequest("GET", "/", nil)
    rec := httptest.NewRecorder()

    Handle(rec, req)

    if rec.Code != 200 {
        t.Errorf("Expected 200, got %d", rec.Code)
    }
}

func TestHandlePOST(t *testing.T) {
    req := httptest.NewRequest("POST", "/", strings.NewReader(`{"name":"test"}`))
    rec := httptest.NewRecorder()

    Handle(rec, req)

    if rec.Code != 200 && rec.Code != 201 {
        t.Errorf("Expected 200 or 201, got %d", rec.Code)
    }
}
Run tests:
go test ./...

Differences from Production

Local development differs from production in some ways:
FeatureLocalProduction
NetworklocalhostGlobal edge network
SecretsEnvironment variablesEncrypted storage
BindingsMocked/simulatedConnected to services
Cold startsN/AContainer initialization
Resource limitsYour machinePlatform limits

Deploy When Ready

Once your function works locally, deploy to Telnyx:
telnyx-edge ship
Your function is now live on the edge network.

Best Practices

Project Structure

my-function/
├── func.toml           # Function configuration
├── function/           # Function code (Python)
│   └── __init__.py
├── pyproject.toml      # Dependencies (Python)
├── .env                # Local env vars (gitignored)
├── .gitignore
└── tests/
    └── test_handler.py # Unit tests

Git Ignore

# Local development
.env
.env.local

# Dependencies
__pycache__/
node_modules/
vendor/

# Build artifacts
dist/
build/
*.pyc
target/

Keep Parity

  • Use the same language version locally as production
  • Match dependency versions
  • Test with production-like request payloads