Functions Microservice
How to deploy, configure, and use the Prisme.ai Functions Microservice for running custom NodeJS and Python code in your applications
The Functions Microservice enables you to execute custom code (NodeJS or Python) within your Prisme.ai applications. This powerful capability allows you to extend the platform with custom logic, integrate with external systems, and implement complex business processes.
Overview
The Functions Microservice provides a secure, isolated environment for running custom code within the Prisme.ai platform. It supports:
- NodeJS Functions: JavaScript code execution with access to selected built-in modules
- Python Functions: Python code execution with standard library access
- Shared Execution Context: Functions within the same workspace can call each other
- Memory Management: Configurable resource limits and garbage collection
- Dependency Management: Automatic installation of required packages
The Functions Microservice is designed with security in mind, running code in isolated environments with configurable resource limits to prevent abuse or resource exhaustion.
Installation Prerequisites
Before deploying the Functions Microservice, ensure you have:
NPM Registry Access
The service must have access to a npm registry for installing JavaScript dependencies. You can use the NPM_CONFIG_REGISTRY
environment variable to specify your own registry.
Storage Volume
The service requires a volume for storing code, dependencies, and execution data. We recommend using volumes with high I/O performance as they may experience heavy usage when installing dependencies.
Configuration
Environment Variables
Configure the Functions Microservice with the following environment variables:
Resource Considerations
When deploying the Functions Microservice, consider the following resource recommendations:
Memory Allocation
Allocate sufficient memory based on your expected workload:
- Minimum: 1GB
- Recommended: 2GB or more for production environments
- Consider additional memory if functions will process large datasets
CPU Resources
Ensure adequate CPU resources:
- Minimum: 0.5 vCPU
- Recommended: 1 vCPU or more for production environments
- Functions with complex calculations may benefit from additional CPU
Disk Space
Plan for storage requirements:
- Minimum: 1GB
- Recommended: 5GB or more for environments with many dependencies
- Consider storage needs for dependency caching and function code
Network Configuration
Ensure proper network setup:
- Accessible by other microservices (especially API Gateway)
- Access to required external resources (NPM registry, etc.)
- Consider network policies for security
Microservice Testing
After deploying the Functions Microservice, verify its operation with these simple tests:
Create a Test Function
Create a function workspace named test
containing a hello
function:
If successful, the same body should be returned in the response.
Execute the Function
Run the function with a test parameter:
If successful, you should receive a response like:
Verify Resource Limits
Test that resource limits are enforced by creating a function that attempts to use excessive resources:
When executing this function, it should terminate due to resource limits or timeout:
If all tests pass, congratulations! Your Functions Microservice is up and running correctly.
Advanced Features
The Functions Microservice includes several advanced capabilities that enhance its flexibility and power:
Integration with Prisme.ai
The Functions Microservice integrates with other Prisme.ai components:
AI Builder
Within AI Builder, you can create custom automations that execute functions, allowing you to extend workflows with custom logic.
AI Knowledge
Custom functions can be used as tools in AI Knowledge agents, enabling them to perform specialized operations like data transformation or external API calls.
AI Store
Functions can power features in agents published to the AI Store, adding custom capabilities to shared agents.
Custom Code App
The Custom Code app provides a user-friendly interface for managing, testing, and monitoring functions.
Security Considerations
When deploying and using the Functions Microservice, keep these security considerations in mind:
Code Isolation
Functions run in isolated environments to prevent interference between different workspaces and functions.
Resource Limits
Configure appropriate resource limits to prevent denial-of-service attacks or resource exhaustion.
Access Control
Implement proper authentication and authorization to control who can create and execute functions.
Dependency Scanning
Consider scanning dependencies for vulnerabilities before allowing their installation.
Function code is executed in a restricted environment, but it still has access to specified Node.js built-in modules and network resources. Be careful when allowing users to create functions, and consider implementing additional security controls for sensitive environments.
Troubleshooting
Was this page helpful?