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
Create a CLI Tool with Node.js
Create a professional Node.js CLI tool with Commander.js, Inquirer, visual feedback, and npm publishing.
Generate Mocks and Fixtures for Your Automated Tests
A prompt to automatically generate realistic mocks, stubs and data fixtures adapted to your test framework and use cases.
Mistral Prompt to Generate JavaScript Code
Mistral, the language model developed by the French startup Mistral AI, has quickly established itself as a powerful alternative for code generation. Thanks to its optimized architecture and training on vast code source corpora, Mistral particularly excels at producing clean, functional, and well-structured JavaScript code. Whether you are developing a web application, a Node.js script, or a front-end library, knowing how to formulate the right prompt is key to obtaining professional-quality code. A well-constructed prompt allows Mistral to precisely understand your technical need, execution context, performance constraints, and coding conventions to follow. In this guide, we offer optimized and tested prompts to get the most out of Mistral for your JavaScript projects. Each prompt is designed to produce maintainable, commented code that follows modern JavaScript development best practices, including error handling, modularity, and ES6+ compatibility.
Progressive Rollout Strategy
Progressive deployment of a new model