This project implements a serverless function for form processing and PDF generation using AWS Lambda.
- Process form submissions securely
- Generate offer letter PDFs on demand
- Stateless architecture with no persistent storage
- CORS-enabled API endpoints
- Open the AWS Console and navigate to SNS
- Click "Create topic"
- Select "Standard" type
- Name:
JobApplicationNotifications - Click "Create topic"
- Copy the Topic ARN for later use
- Navigate to AWS Lambda
- Click "Create function"
- Select "Author from scratch"
- Name:
formHandler - Runtime:
Node.js 14.x - Architecture:
x86_64 - Click "Create function"
- In the function page, scroll to "Code source"
- Delete the default code in
index.js - Copy and paste the code from our
index.jsfile - Click "Deploy"
- In the Lambda function page, click "Layers"
- Click "Create layer"
- Name:
pdf-dependencies - Upload a ZIP file containing node_modules with pdfkit and aws-sdk
npm install pdfkit aws-sdk zip -r layer.zip node_modules - Compatible runtimes: Select
Node.js 14.x - Click "Create"
- Go back to your function and add this layer
- In the Lambda function page, click "Configuration"
- Click "Environment variables"
- Click "Edit"
- Add key:
SNS_TOPIC_ARNwith value: [Your SNS Topic ARN] - Click "Save"
- In the Lambda function page, click "Configuration"
- Click "Permissions"
- Click the role name to open the IAM console
- Click "Add permissions" > "Create inline policy"
- Service:
SNS - Actions:
Publish - Resources: Add your SNS Topic ARN
- Click "Review policy"
- Name:
SNSPublishPolicy - Click "Create policy"
- Navigate to API Gateway
- Click "Create API"
- Select "REST API" and click "Build"
- API name:
FormProcessingAPI - Click "Create API"
-
Click "Create Resource"
-
Resource Name:
process-form -
Click "Create Resource"
-
With
/process-formselected, click "Create Method" -
Select
POSTand click the checkmark -
Integration type:
Lambda Function -
Lambda Function:
formHandler -
Click "Save"
-
Click "Create Resource" again
-
Resource Name:
generate-pdf -
Click "Create Resource"
-
With
/generate-pdfselected, click "Create Method" -
Select
POSTand click the checkmark -
Integration type:
Lambda Function -
Lambda Function:
formHandler -
Click "Save"
- For each resource (
/process-formand/generate-pdf):- Select the resource
- Click "Actions" > "Enable CORS"
- Check "Access-Control-Allow-Origin" and enter
* - Click "Enable CORS and replace existing CORS headers"
- Click "Actions" > "Deploy API"
- Deployment stage: [New Stage]
- Stage name:
dev - Click "Deploy"
- Note the "Invoke URL" - this is your API endpoint
- Open
frontend-example.html - Update the API_ENDPOINTS object with your API Gateway URLs:
const API_ENDPOINTS = { processForm: 'https://your-api-id.execute-api.region.amazonaws.com/dev/process-form', generatePdf: 'https://your-api-id.execute-api.region.amazonaws.com/dev/generate-pdf' };
-
Install dependencies:
npm install -
Run the test script:
node test.js
- Use the provided test JSON files with curl or Postman:
curl -X POST -H "Content-Type: application/json" -d @test-form.json https://your-api-id.execute-api.region.amazonaws.com/dev/process-form
If you prefer using the Serverless Framework instead of manual setup:
-
Install Serverless Framework:
npm install -g serverless -
Configure AWS credentials:
serverless config credentials --provider aws --key YOUR_ACCESS_KEY --secret YOUR_SECRET_KEY -
Deploy:
./deploy.sh
- All functions are stateless
- No data is stored persistently
- API Gateway provides request validation
- IAM roles limit function permissions