Prompt to Create Optimized Serverless Functions
A complete prompt to design production-ready serverless functions on Vercel or AWS Lambda, covering code, security, performance and deployment.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Tu es un expert en architectures serverless spécialisé dans [PLATEFORME : Vercel Functions / AWS Lambda / les deux]. Je développe une application [TYPE_APPLICATION : ex. SaaS B2B, e-commerce, API publique, application mobile backend] et j'ai besoin de concevoir des serverless functions pour le cas d'usage suivant :
Contexte fonctionnel : [DESCRIPTION_FONCTIONNALITE : ex. traitement de webhooks Stripe, génération de PDF, envoi d'emails transactionnels, CRON de synchronisation de données]
Stack technique : [STACK : ex. Next.js 14 App Router, Node.js 20, Python 3.12, TypeScript]
Contraintes :
- Runtime : [RUNTIME : Node.js / Python / Go / Rust]
- Temps d'exécution max : [TIMEOUT : ex. 10s, 30s, 5min]
- Mémoire allouée : [MEMOIRE : ex. 128MB, 512MB, 1024MB]
- Volume estimé : [VOLUME : ex. 100 req/min, 10K/jour, pics à 1000 req/s]
Génère le code complet de la function avec :
- Structure du handler — Point d'entrée optimisé avec typage strict, parsing et validation de l'input (utilise zod ou équivalent)
- Gestion des erreurs — Try/catch structuré, codes HTTP appropriés, messages d'erreur exploitables sans fuite d'information sensible
- Optimisation cold start — Initialisation des clients (DB, SDK) en dehors du handler, lazy loading des dépendances lourdes, tree-shaking
- Sécurité — Validation des headers d'authentification, vérification de signature webhook si applicable, rate limiting, CORS
- Observabilité — Logging structuré (JSON), métriques custom, trace ID pour le debugging distribué
- Configuration — Variables d'environnement requises avec valeurs par défaut sûres, fichier de config séparé
- Tests — Un test unitaire du handler et un test d'intégration avec mocks des services externes
- Déploiement — Configuration de déploiement (vercel.json ou serverless.yml ou SAM template) avec les settings de mémoire, timeout et environnement
Pour chaque section, explique les choix techniques et les pièges courants à éviter. Indique les coûts estimés pour le volume spécifié.
Personalize this prompt with Léa
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Why this prompt works
<p>This prompt guides AI to produce <strong>complete, production-ready serverless functions</strong>. By specifying your target platform (Vercel or AWS Lambda), tech stack and performance constraints, you get structured code following serverless best practices: cold start management, optimized connection initialization, and deployment configuration.</p><p>The <strong>bracketed variables</strong> let you adapt the prompt to your exact context. The <code>[VOLUME]</code> field is particularly important as it influences recommendations on allocated memory, provisioned concurrency, and cost estimation. Also specify the <code>[TIMEOUT]</code> as strategies differ radically between a fast API function (3-10s) and a long batch process (up to 15min on AWS).</p><p>For optimal results:</p><ul><li><strong>Be specific about the use case</strong> — a Stripe webhook and a REST API don't have the same security and retry patterns</li><li><strong>Mention your external services</strong> (database, S3, third-party APIs) so the AI optimizes connections and pooling</li><li><strong>Iterate on tests</strong> — then request load scenarios and resilience tests (external timeout, network errors)</li></ul>
Use Cases
Expected Output
Complete, commented code for the serverless function with its handler, tests, deployment configuration, and explanations of architecture choices, performance optimizations and cost estimation.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
- LéaAI
Pensez à préciser la structure de sortie attendue : monofichier pour Vercel Functions, ou projet complet avec SAM pour AWS Lambda ? Ajoutez aussi les versions exactes des dépendances (Next.js, SDK Stripe, zod…) et un exemple de payload d’entrée/sortie. Cela évitera les réponses approximatives et facilitera l’intégration directe dans votre codebase.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
Design a Robust Microservices Architecture
A complete prompt to design a professional microservices architecture covering DDD decomposition, inter-service communication, Kubernetes deployment, and observability.
GitHub Copilot Prompt for Documenting Code
Code documentation is often neglected by developers, yet it is a fundamental pillar of software maintainability. GitHub Copilot, integrated directly into your code editor, turns this time-consuming task into a smooth and nearly instant process. By analyzing your code context — function names, parameters, return types, internal logic — Copilot generates relevant comments, docstrings, and technical documentation in seconds. Whether you are working on a REST API, an open-source library, or a corporate project, a well-crafted prompt enables Copilot to produce structured, consistent documentation that adheres to your language's conventions (JSDoc, Python docstrings, Javadoc, etc.). The challenge is not simply to describe what the code does, but to capture the why — architectural decisions, edge cases, business constraints. With the right prompts, Copilot becomes a true technical co-writer capable of significantly accelerating your documentation workflow without sacrificing quality.
Master Advanced TypeScript Types with AI
A prompt to generate advanced TypeScript types (generics, mapped types, conditional types) with documentation and built-in type tests.
Helm Chart for Application
Create a Helm chart