Error 'Cannot find module aws-sdk' en Lambda: migra a SDK v3

¿Error Cannot find module aws-sdk al migrar Lambda a Node 18? Descubre por qué ocurre y cómo migrar a @aws-sdk v3 para solucionarlo definitivamente.

6 jul 2026 • 2 min read • Q2BSTUDIO Team

Migración de Lambda a Node 18: cómo solucionar el error de aws-sdk

Al actualizar una función Lambda de nodejs16.x a nodejs18.x (o versiones superiores), es habitual encontrarse con el error 'Cannot find module 'aws-sdk''. Esto no es un fallo en la instalación local, sino que AWS decidió eliminar el paquete monolítico aws-sdk v2 del runtime a partir de nodejs18.x. La versión v2, que había estado disponible sin necesidad de empaquetado, dejó de recibir soporte en septiembre de 2025, por lo que su uso continuado supone un riesgo de seguridad. La solución definitiva es migrar al SDK v3, que adopta un enfoque modular: en lugar de un único paquete de ~75 MB, se instalan solo los servicios necesarios mediante paquetes @aws-sdk/*. Esto no solo reduce el peso de las funciones, sino que también mejora la eficiencia en el inicio en frío. Muchas empresas que han desarrollado aplicaciones a medida con Lambda deben revisar sus importaciones y adaptar sus servicios, lo que puede automatizarse con herramientas como el codemod oficial de AWS.

La migración a SDK v3 implica cambios en la forma de invocar cada servicio: se importan clases Client y Command específicas, se usa client.send() en lugar de .promise(), y se abandonan los patrones de callback. Por ejemplo, para DynamoDB se emplea @aws-sdk/lib-dynamodb, que ofrece una API similar a DocumentClient. Es fundamental escanear el código con grep para localizar todas las referencias a require('aws-sdk') antes de cambiar el runtime. Si se necesita un parche temporal, es posible empaquetar aws-sdk v2 en el ZIP o en una capa, pero esto añade latencia y mantiene una dependencia sin soporte. Para proyectos que usan esbuild, hay que forzar el empaquetado con la opción --packages=bundle, ya que versiones recientes tratan node_modules como externas por defecto.

En el ecosistema de servicios cloud AWS y Azure, mantener las funciones actualizadas es crítico para la ciberseguridad y el rendimiento. Q2BSTUDIO, como empresa especializada en desarrollo de software, ofrece consultoría para modernizar arquitecturas serverless, incorporando ia para empresas, servicios inteligencia de negocio como Power BI, y agentes IA que optimizan procesos. La transición a SDK v3 no solo resuelve el error inmediato, sino que prepara las funciones para integrar nuevas capacidades como el manejo nativo de promesas y el soporte para TypeScript, facilitando la creación de software a medida robusto y escalable. Si su equipo necesita asistencia para migrar librerías, auditar dependencias o rediseñar flujos serverless, contar con un partner tecnológico experimentado acelera el proceso y evita interrupciones en producción.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat