Back to skills
SKILL.md
Serverless Function Generator
ASecurityScaffold lightweight serverless handlers for Cloudflare Workers or AWS Lambda with standard CORS and error handling.
- 2 stars
- 0 votes
- 0 copies
- 0 views
- Added September 27, 2026
Works with
Security analysis
92/100- Installs packages at runtime which could introduce malicious dependencies
npx -y skills add RMAzrim/opencode-artes --skill serverless-function-generator --agent claude-codeAre you the author of Serverless Function Generator?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/rmazrim-serverless-function-generator)---
name: Serverless Function Generator
description: Scaffold lightweight serverless handlers for Cloudflare Workers or AWS Lambda with standard CORS and error handling.
metadata:
source: skills/serverless-function-generator/serverless-function-generator.md
---
# Serverless Function Generator
## Prerequisites & Dependencies
- Node.js 18+ with npm or pnpm
- Cloudflare Wrangler (for Workers): `npm i -g wrangler` or AWS SAM/Serverless Framework (for Lambda)
- AWS CLI configured (for Lambda) or a Cloudflare account API token
- Optional: `npm i pino` for structured logging
## Execution Steps
1. Choose your target platform: Cloudflare Workers (JavaScript/TypeScript) or AWS Lambda (Node.js)
2. Scaffold the project: `wrangler init my-worker` (Workers) or `mkdir my-lambda && cd my-lambda`
3. Create the handler file: implement the core function with a consistent signature `(request) => Response`
4. Add standardized CORS headers: `Access-Control-Allow-Origin: *`, `Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS`, `Access-Control-Allow-Headers: Content-Type, Authorization`
5. Implement error handling: wrap logic in `try/catch`, return structured JSON error responses with `statusCode` and `body`, and set appropriate HTTP status codes (400, 401, 404, 500)
6. Add health check endpoint: `GET /healthz` that returns `200 OK` with `{ status: "ok" }`
7. Deploy and test: `wrangler publish` (Workers) or `aws lambda create-function` (Lambda), then invoke and verify headers/body
```javascript
// Cloudflare Worker: scaffolded handler with CORS and error handling
export default {
async fetch(request, env, ctx) {
// CORS preflight
if (request.method === 'OPTIONS') {
return new Response(null, {
status: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
});
}
try {
const url = new URL(request.url);
// Health check
if (url.pathname === '/healthz') {
return new Response(JSON.stringify({ status: 'ok' }), {
headers: { 'Content-Type': 'application/json' },
status: 200,
});
}
// Example route handling
if (request.method === 'GET' && url.pathname === '/api/time') {
return new Response(JSON.stringify({ time: new Date().toISOString() }), {
headers: { 'Content-Type': 'application/json' },
status: 200,
});
}
// 404 fallback
return new Response('Not Found', { status: 404 });
} catch (error) {
// Structured error response
return new Response(
JSON.stringify({ error: 'Internal Server Error', message: error.message }),
{
headers: { 'Content-Type': 'application/json' },
status: 500,
}
);
}
},
};
```
```bash
# Deploy Cloudflare Worker
wrangler publish
# Or deploy AWS Lambda with SAM
sam build
sam deploy --guided
```
Attribution
Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.