Skip to content
Back to skills

Serverless Function Generator

ASecurity

Scaffold 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
developmentjavascripttypescriptjavabashnodeawsapi

Works with

  • cli
  • api

Security analysis

A92/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned September 27, 2026

npx -y skills add RMAzrim/opencode-artes --skill serverless-function-generator --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Serverless Function Generator?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Serverless Function Generator
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/rmazrim-serverless-function-generator/badge)](https://www.skillsdirectory.com/skills/rmazrim-serverless-function-generator)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.