Building Lambda-Based PDF Reports Under Pressure
The Challenge
During my time at Koridor, a lawyer client approached us with an urgent project. They needed to improve their HR system for hiring candidates. The system worked by having applicants answer questions based on 7 key attributes, then generating an automated report to evaluate if they were the right fit for the company.
The Challenge:
- Build PDF report generation system evaluating candidates on 7 key attributes
- Deliver within 2 weeks
- Continue working on my portion of the web app simultaneously
- Ensure reliability and scalability with serverless architecture
- Maintain tight integration with existing platform
- Meet strict performance requirements (8-15 second generation time)
This was a true test of working under pressure while maintaining code quality and meeting client expectations.
The Solution: Serverless Architecture
I chose AWS Lambda for PDF generation because:
- Scalability: Automatically handles concurrent report requests
- Cost-Effective: Pay only for execution time
- Reliability: Built-in error handling and retry logic for temporary failures
- Integration: Easy to connect with API Gateway for secure access
- Performance: Optimized to generate reports in 8-15 seconds
Technical Implementation
Local Development Strategy
Before deploying to Lambda, I built a local Express server that simulated the Lambda environment. This let me test the entire PDF generation flow without deploying, debug issues faster, and validate the report format with real data samples. This approach saved significant Lambda invocation costs during development and enabled rapid iteration on the report structure.
PDF Generation with Node.js (HTML-to-PDF)
I used Puppeteer to convert HTML to PDF, which let me design reports using familiar HTML/CSS syntax. This approach gave me full control over styling and layout, and I could create reusable template components for consistent formatting. The process involved generating HTML content from candidate data, loading it into a headless browser, and converting it to PDF with proper margins and formatting.
AWS Lambda Deployment
The Lambda handler validated input data, generated the PDF report, and returned it as a base64-encoded string for API Gateway. I implemented proper error handling to catch and log issues, returning appropriate HTTP status codes. The function was configured with sufficient memory (1GB) to handle Puppeteer's requirements.
API Gateway Integration
I configured API Gateway with AWS IAM authentication to ensure only authorized clients could access the endpoint. The integration used the AWS_PROXY type, which automatically forwarded requests to Lambda and handled responses, simplifying the setup while maintaining security.
Performance Optimization
Key Optimizations:
- Optimized Puppeteer Init: Reduced cold start times significantly
- Base64 Encoding: Efficiently handled large PDF payloads for API Gateway responses
- Retry Logic: Built robust error handling for temporary Lambda failures
- Parallel Processing: Generate multiple report sections simultaneously
- Caching: Cache frequently used templates and styles
- Font Optimization: Use system fonts to reduce size
- Memory Tuning: Optimized browser settings for Lambda environment constraints
Results & Impact
Successful Delivery:
- ✅ Delivered within 2-week deadline while maintaining web app development
- ✅ Integrated seamlessly with existing HR platform via API Gateway
- ✅ Generated reports in 8-15 seconds consistently
- ✅ Zero errors during initial rollout
- ✅ Client satisfied with quality and speed
- ✅ Project led to additional work opportunities with the client
Technical Achievements:
- Serverless architecture for automatic scalability
- Cost-effective solution (pay-per-use model)
- Secure API Gateway integration with on-demand access
- Professional PDF formatting with algorithm results across 7 key attributes
- Reusable Lambda functions for future enhancements
- Easy to maintain and extend
Lessons Learned
What Worked Well:
- Local-first development saved time and money
- Mock data testing caught issues before deployment
- Modular architecture made debugging easier
- API Gateway security ensured only authorized access
Challenges Overcome:
- Lambda timeout limits - Optimized Puppeteer initialization
- Memory constraints - Tuned browser settings for Lambda environment
- Cold starts - Implemented connection pooling
- Base64 encoding - Handled large PDF responses efficiently
Key Takeaways
- Pressure can be productive when you have a clear plan, stay organized, and prioritize reliability
- Local development with mocks is crucial for debugging complex systems quickly
- Serverless architecture provides scalability without infrastructure management overhead
- Iterative testing with real data samples builds confidence before deployment
- Performance optimization matters - achieving 8-15 second generation times required careful tuning
- Client trust is earned by delivering quality work under tight deadlines while maintaining other responsibilities
Conclusion
This project demonstrated that with proper planning, modern serverless tools, and a methodical approach, it's possible to build high-quality solutions under pressure. The Lambda-based PDF generation system not only met the client's immediate needs but also provided a scalable foundation for future growth.
The experience reinforced my belief in building robust, production-ready solutions regardless of timeline constraints—a principle I carry with me in every project.