Constants
Constants provide secure storage for API keys, passwords, database URLs, and other configuration values used by your Buzzy applications and Functions. Secret constants are encrypted using AES encryption to ensure sensitive data remains protected.
What are Constants?
Constants are key-value pairs that store configuration data for your applications:
API Keys: Store authentication tokens for external services
Database URLs: Connection strings for external databases
Configuration Values: Base URLs, default settings, and other config
Passwords: Encrypted storage for sensitive credentials
Environment Settings: Different values for development, staging, production
Types of Constants
Regular Constants
Stored as plain text
Suitable for non-sensitive configuration
Examples: API base URLs, default settings, public configuration
Secret Constants
Encrypted using AES encryption with a secure key
Automatically encrypted when marked as "secret"
Examples: API keys, passwords, database credentials, private tokens
Creating Constants
Through the UI
Navigate to your app's Constants panel
Click "Add Constant"
Configure the constant:
Name: Unique identifier (e.g.,
API_KEY
,DATABASE_URL
)Value: The actual value to store
Description: What this constant is used for
Secret: Check if this should be encrypted
Click "Create Constant"
Naming Conventions
Use descriptive, uppercase names with underscores:
OPENAI_API_KEY
STRIPE_SECRET_KEY
DATABASE_URL
EMAIL_SERVICE_PASSWORD
API_BASE_URL
Using Constants in Functions
Constants can be referenced in Function environment variables using the BUZZYCONSTANTS()
syntax:
Direct Reference
// In Function environment variable configuration
API_KEY = BUZZYCONSTANTS('OPENAI_API_KEY')
BASE_URL = BUZZYCONSTANTS('API_BASE_URL')
Dot Notation
// Alternative syntax
API_KEY = BUZZYCONSTANTS.OPENAI_API_KEY
BASE_URL = BUZZYCONSTANTS.API_BASE_URL
In Function Code
export const main = async (event) => {
// Access the resolved values through environment variables
const apiKey = process.env.API_KEY;
const baseUrl = process.env.BASE_URL;
const response = await axios.post(`${baseUrl}/api/endpoint`, {
data: event.body
}, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
});
return {
statusCode: 200,
body: response.data
};
};
Security Features
AES Encryption
Secret constants are encrypted using AES encryption:
Encryption key is stored securely on the server
Values are encrypted before storage in the database
Automatic decryption when accessed by authorized functions
No plain text storage of sensitive values
Access Control
Constants are scoped to individual applications
Only users with edit permissions can view/modify constants
Secret values are masked in the UI by default
Audit trail for constant creation and modification
Best Practices
Always mark sensitive data as "secret"
Use descriptive names that indicate the purpose
Regularly rotate API keys and update constants
Don't include secrets in function code or comments
Managing Constants
Viewing Constants
Constants panel shows all constants for your app
Secret values are masked with asterisks by default
Click the eye icon to temporarily reveal secret values
Non-secret values are always visible
Editing Constants
Click the edit icon next to a constant
Modify the name, value, description, or secret status
Click "Save" to update the constant
Functions using this constant will automatically get updated values
Deleting Constants
Click the delete icon next to a constant
Confirm deletion in the dialog
Warning: Deleting a constant may break functions that depend on it
Common Use Cases
API Integration
// Constants
OPENAI_API_KEY (secret) = "sk-..."
OPENAI_BASE_URL = "https://api.openai.com/v1"
OPENAI_MODEL = "gpt-4"
// Function environment variables
OPENAI_API_KEY = BUZZYCONSTANTS('OPENAI_API_KEY')
OPENAI_BASE_URL = BUZZYCONSTANTS('OPENAI_BASE_URL')
OPENAI_MODEL = BUZZYCONSTANTS('OPENAI_MODEL')
Database Connection
// Constants
DB_HOST = "your-database-host.com"
DB_NAME = "production_db"
DB_USER = "api_user"
DB_PASSWORD (secret) = "secure_password"
// Function environment variables
DATABASE_URL = BUZZYCONSTANTS('DB_HOST')
DATABASE_NAME = BUZZYCONSTANTS('DB_NAME')
DATABASE_USER = BUZZYCONSTANTS('DB_USER')
DATABASE_PASSWORD = BUZZYCONSTANTS('DB_PASSWORD')
Multi-Environment Setup
// Development Constants
API_BASE_URL = "https://api-dev.example.com"
DEBUG_MODE = "true"
// Production Constants
API_BASE_URL = "https://api.example.com"
DEBUG_MODE = "false"
Webhook Configuration
// Constants
STRIPE_WEBHOOK_SECRET (secret) = "whsec_..."
STRIPE_PUBLISHABLE_KEY = "pk_..."
STRIPE_SECRET_KEY (secret) = "sk_..."
// Function environment variables
WEBHOOK_SECRET = BUZZYCONSTANTS('STRIPE_WEBHOOK_SECRET')
STRIPE_PK = BUZZYCONSTANTS('STRIPE_PUBLISHABLE_KEY')
STRIPE_SK = BUZZYCONSTANTS('STRIPE_SECRET_KEY')
Advanced Features
Formula Support
Constants support JSONata expressions for dynamic values:
// Dynamic timestamp
CURRENT_DATE = $now()
// Conditional values
API_ENDPOINT = $boolean(DEBUG_MODE) ? "https://api-dev.com" : "https://api.com"
Constant References
Constants can reference other constants:
// Base configuration
API_HOST = "api.example.com"
API_VERSION = "v1"
// Derived values
API_BASE_URL = "https://" & API_HOST & "/" & API_VERSION
Troubleshooting
Common Issues
Constant not found error
Verify the constant name is spelled correctly
Check that the constant exists in the current app
Ensure proper syntax:
BUZZYCONSTANTS('CONSTANT_NAME')
Secret value not decrypting
Verify the constant is marked as secret
Check server encryption key configuration
Ensure proper permissions to access the constant
Function environment variable empty
Check the BUZZYCONSTANTS() reference syntax
Verify the constant exists and has a value
Test with a simple, non-secret constant first
Best Practices for Debugging
Test with non-secret constants first to verify syntax
Use descriptive constant names to avoid confusion
Check function logs for environment variable values (excluding secrets)
Verify constant values in the Constants panel before deployment
Security Considerations
Never log secret values in function code
Rotate API keys regularly and update constants
Use least-privilege access for external API keys
Monitor constant access through audit logs
Backup important constants before making changes
Migration and Backup
Exporting Constants
While there's no direct export feature, you can:
Document constant names and descriptions
Keep a secure backup of non-secret values
Maintain a list of secret constants for reference
Moving Between Apps
Constants are app-specific and must be recreated when:
Moving functions between apps
Creating new environments
Setting up development/staging/production instances
Version Control
Consider maintaining a configuration file with:
Constant names and descriptions
Non-secret default values
Documentation of what each constant is used for
Environment-specific variations
Last updated