P
💻DeveloppementAdvancedAll AIs

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 :

  1. Structure du handler — Point d'entrée optimisé avec typage strict, parsing et validation de l'input (utilise zod ou équivalent)
  2. Gestion des erreurs — Try/catch structuré, codes HTTP appropriés, messages d'erreur exploitables sans fuite d'information sensible
  3. Optimisation cold start — Initialisation des clients (DB, SDK) en dehors du handler, lazy loading des dépendances lourdes, tree-shaking
  4. Sécurité — Validation des headers d'authentification, vérification de signature webhook si applicable, rate limiting, CORS
  5. Observabilité — Logging structuré (JSON), métriques custom, trace ID pour le debugging distribué
  6. Configuration — Variables d'environnement requises avec valeurs par défaut sûres, fichier de config séparé
  7. Tests — Un test unitaire du handler et un test d'intégration avec mocks des services externes
  8. 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

Create a serverless REST API with JWT authentication and database connectionDevelop a secure Stripe webhook handler with signature verificationSet up a serverless CRON for data synchronization between servicesDesign a function for on-the-fly image processing or PDF generation

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 Optimizer

Comments

  • 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

💻DeveloppementIntermediateChatGPT

ChatGPT Prompt for Generating Python Code

ChatGPT has become an indispensable tool for Python developers, whether beginners or experienced. Thanks to its advanced understanding of natural language, it can transform a functional description into clean, structured, and functional Python code in seconds. But the quality of the generated code depends directly on the quality of the prompt used. A vague prompt will produce generic and often unusable code, while a well-structured prompt will generate production-ready code with error handling, typing, and documentation. In this guide, we provide optimized prompts to get the most out of ChatGPT for generating Python code. Whether you need to write an automation script, a REST API, a data processing algorithm, or a complex class, these prompts will help you obtain precise and professional results. The goal is to save you time while maintaining a high level of quality, guiding ChatGPT with the right instructions so that it respects PEP 8 conventions, includes docstrings, and produces maintainable code.

0317
💻DeveloppementIntermediateAll AIs

Generate Complete Technical Documentation for Your Code

A complete prompt to generate structured and professional technical documentation, adapted to the target audience and project type.

0477
💻DeveloppementAdvancedChatGPT

Master Advanced TypeScript Types

Strengthen your code's type safety with advanced generics, utility types, and discriminated unions.

39594
💻DeveloppementAdvancedAll AIs

Kubernetes Backup Strategy

Kubernetes Disaster Recovery Plan

0187