This project contains an AWS Lambda function that renders HTML content to an image using Puppeteer and the @sparticuz/chromium package. The project is deployed using AWS CDK.
- Render HTML content to PNG or JPEG images
- Return images as base64-encoded strings or upload to S3 and return a signed URL
- Configure viewport size, image quality, and other rendering options
- Deployed with API Gateway for easy access
This project was developed using:
- Cursor.sh v0.47.6 - An AI-powered code editor
- Amazon Q CLI - AWS's AI-powered developer tool
- AWS CDK - Infrastructure as Code tool for AWS
The project includes:
- HTML to Image Lambda Function: Renders HTML to images using Puppeteer and Chromium
- S3 Bucket: Stores generated images when requested
- API Gateway: Provides HTTP endpoints to access the Lambda functions
- Simple HTML Renderer: A basic Lambda function that returns HTML content (for testing)
Endpoint: POST /render-image
Request Body:
{
"html": "base64-encoded-html-content",
"outputType": "base64", // or "s3"
"imageFormat": "png", // or "jpeg"
"imageQuality": 80, // For JPEG only (1-100)
"viewportWidth": 1280,
"viewportHeight": 800,
"fullPage": false // Set to true to capture the full scrollable page
}Response (base64 mode):
{
"message": "Screenshot generated successfully",
"imageFormat": "png",
"image": "base64-encoded-image"
}Response (S3 mode):
{
"message": "Screenshot saved to S3",
"url": "signed-s3-url",
"key": "s3-object-key"
}Endpoint: GET /render?name=YourName
Returns a simple HTML page with the provided name parameter.
To deploy this project:
npm install
npm run build
npx cdk deployTo test the function locally:
npm run build
npx cdk synth- The S3 bucket is configured to automatically delete objects after 7 days
- The Lambda function has a 30-second timeout and 2GB of memory
- For production use, consider adjusting the S3 bucket's removal policy and lifecycle rules
This includes an MCP server, which we can run as:
.venv/bin/mcp run server.py