Skip to main content

Function Configuration

Configure your Edge Compute functions with environment variables, secrets, and deployment settings for different environments.

Configuration File (func.toml)

Each function includes a func.toml configuration file:
[edge_compute]
func_id = "func-abc123def456"
func_name = "hello-world"

[env_vars]
MY_KEY = "VAL"

Environment Variables

Setting Environment Variables

Via Configuration File

[env_vars]
API_BASE_URL = "https://api.example.com"
CACHE_TTL = "3600"
DEBUG = "false"
WEBHOOK_SECRET = "your-webhook-secret"

Accessing Environment Variables

Python

import os

async def handler(request):
    api_url = os.environ.get("API_BASE_URL")
    debug = os.environ.get("DEBUG", "false").lower() == "true"
    cache_ttl = int(os.environ.get("CACHE_TTL", "300"))
    webhook_secret = os.environ.get("WEBHOOK_SECRET")
    
    return {
        "api_configured": bool(api_url),
        "webhook_configured": bool(webhook_secret),
        "cache_ttl": cache_ttl,
        "debug": debug
    }

Go

import (
    "os"
    "strconv"
)

func handler(w http.ResponseWriter, r *http.Request) {
    apiURL := os.Getenv("API_BASE_URL")
    debug, _ := strconv.ParseBool(os.Getenv("DEBUG"))
    cacheTTL, _ := strconv.Atoi(os.Getenv("CACHE_TTL"))
    webhookSecret := os.Getenv("WEBHOOK_SECRET")
    
    if cacheTTL == 0 {
        cacheTTL = 300 // default value
    }
    
    response := map[string]interface{}{
        "api_configured": apiURL != "",
        "webhook_configured": webhookSecret != "",
        "cache_ttl": cacheTTL,
        "debug": debug,
    }
    
    json.NewEncoder(w).Encode(response)
}

Secrets Management

Storing Secrets

Use the CLI to securely store sensitive data:
# Add secrets
telnyx-edge secrets add DATABASE_PASSWORD "super-secret-password"
telnyx-edge secrets add API_TOKEN "sensitive-api-token"
telnyx-edge secrets add ENCRYPTION_KEY "32-character-key-for-encryption"

# List secrets (values are never shown)
telnyx-edge secrets list

# Remove secrets
telnyx-edge secrets delete OLD_API_TOKEN

Accessing Secrets

Secrets are available as environment variables in your function:

Best Practices for Secrets

DO:
  • Store sensitive data as secrets, not environment variables.
  • Use descriptive names for secrets.
  • Rotate secrets regularly.
  • Use different secrets for different environments.
DON’T:
  • Store secrets in your source code.
  • Log secret values.
  • Share secrets via insecure channels.
  • Use the same secrets across all functions.

Bindings

Bindings enable your edge functions to call Telnyx APIs without managing API keys. Once you create a binding for your organization, your functions can use the Telnyx SDK to access messaging, voice, and other Telnyx services.

Creating a Binding

Create a binding for your organization:
telnyx-edge bindings create
This is a one-time setup per organization.

Managing Bindings

# View your current binding
telnyx-edge bindings get

# Validate the binding is working
telnyx-edge bindings validate

# Rotate binding credentials
telnyx-edge bindings update

# Remove the binding
telnyx-edge bindings delete

Using Telnyx APIs in Your Function

With a binding configured, use the Telnyx SDK in your functions:

Python

import telnyx

async def handler(request):
    message = telnyx.Message.create(
        from_="+15551234567",
        to="+15559876543",
        text="Hello from Edge Compute!"
    )
    
    return {"message_id": message.id}

Go

import "github.com/telnyx/telnyx-go"

func handler(w http.ResponseWriter, r *http.Request) {
    client := telnyx.NewClient()
    
    message, err := client.Messages.Create(&telnyx.MessageParams{
        From: "+15551234567",
        To:   "+15559876543",
        Text: "Hello from Edge Compute!",
    })
    
    json.NewEncoder(w).Encode(message)
}

Bindings vs Secrets

Use bindings for Telnyx API access — credentials are managed automatically. Use secrets for third-party services or when you need multiple different credentials.

Runtime Configuration

Functions run with default resource allocation and timeout settings optimized for typical workloads. Custom resource configuration may be available in future releases.

Configuration Validation

Validating Configuration

Configuration Schema

Define configuration schema for validation:
// config.schema.ts
interface FunctionConfig {
  database: {
    url: string;
    maxConnections: number;
  };
  api: {
    baseUrl: string;
    timeout: number;
  };
  features: {
    debug: boolean;
    caching: boolean;
  };
}

export function validateConfig(): FunctionConfig {
  return {
    database: {
      url: requireEnv('DATABASE_URL'),
      maxConnections: parseInt(process.env.DB_MAX_CONNECTIONS || '10')
    },
    api: {
      baseUrl: requireEnv('API_BASE_URL'),
      timeout: parseInt(process.env.API_TIMEOUT || '5000')
    },
    features: {
      debug: process.env.DEBUG === 'true',
      caching: process.env.ENABLE_CACHE !== 'false'
    }
  };
}

function requireEnv(name: string): string {
  const value = process.env[name];
  if (!value) {
    throw new Error(`Required environment variable ${name} is not set`);
  }
  return value;
}

Configuration Best Practices

Security

  • Use secrets for sensitive data.
  • Validate configuration at startup.
  • Use environment-specific configurations.
  • Never log secret values.

Maintainability

  • Document all configuration options.
  • Use descriptive variable names.
  • Group related settings.
  • Version your configuration files.
Deploy with custom configuration →