.zip) ready for AWS Lambda.
Usage
Examples
Arguments
JavaScript Lambda handler file (must export
handler function)Output deployment package (.zip file)
Handler Function
Your Lambda handler file must export ahandler function:
handler.js
Porffor automatically removes the
async keyword as it compiles synchronous code. The handler is internally wrapped to support Lambda’s requirements.Compilation Process
The Lambda compilation:- Wraps handler: Converts async handler to Porffor-compatible format
- Compiles to C: Uses 2c to generate C source code
- Compiles to native: Produces
bootstrapexecutable - Creates package: Packages
bootstrapinto.zipfile
Optimizations
Porffor optimization level
Debug mode - includes symbols, disables strippingDebug packages:
- Include function names and debug info
- Are larger in size
- Easier to troubleshoot
- Should not be used in production
Compiler Selection
Lambda compilation uses a C compiler. By default:- Checks for
musl-gcc(recommended) - Falls back to
gccif musl-gcc not found - Can be overridden with
CCenvironment variable
Override C compiler
Installing musl-gcc
Lambda Configuration
Porffor uses optimized settings for Lambda:- Allocator:
oneshot(faster cold starts) - Target:
c(via 2c compiler) - Architecture:
x86_64-v3optimized - Stripping: Enabled (unless
-dflag) - Static linking: Enabled with musl-gcc
Package Contents
The generated.zip contains:
bootstrap file is the Lambda custom runtime executable.
Deployment
Return Values
The handler must return either:-
Object - Automatically JSON stringified
-
Bytestring - Returned as-is
Complete Example
Package Size
Optimized Lambda packages are typically:- Simple handler: 50-100 KB
- Medium complexity: 200-400 KB
- Complex logic: 500 KB - 1 MB
Porffor Lambda packages are significantly smaller than typical Node.js Lambda packages because they have zero runtime dependencies.
Performance Benefits
- Fast cold starts: Native executable, no runtime initialization
- Low memory usage: No JavaScript runtime overhead
- Predictable performance: AOT compilation, no JIT warmup
- Small package size: No node_modules dependencies
Optimization Tips
Troubleshooting
musl-gcc Warning
CC=gcc to suppress warning:
Handler Not Found
Ensure your file exportshandler:
Lambda Timeout
Increase timeout in AWS Lambda configuration:Missing Dependencies
Porffor has limited standard library support. Check:Environment Variables
C compiler to use
Debug Mode Details
When using-d flag:
- Unstripped binary with debug symbols
- Function and variable names preserved
- Debug compiler flags (
-g,-O0) - C source file (
.c) retained - Bootstrap binary retained
AWS Lambda Runtimes
Porffor Lambda functions use custom runtimes:provided.al2023(Amazon Linux 2023) - Recommendedprovided.al2(Amazon Linux 2) - Also supported- Architecture:
x86_64
Cleanup
By default, temporary files are removed after packaging:bootstrap.c(C source)bootstrap(before zipping)
-d flag, these files are preserved for inspection.
Next Steps
Native Compilation
Understand the underlying native compilation
C Output
Inspect generated C code
Profile
Optimize handler performance
Run Locally
Test handler before deploying