title: Cannot find module 'nodemailer' in AWS Lambda
body: <p>I have a simple nodejs code to send a test email using AWS Lambda function and SES services.</p>
  
  <p>I was able to deploy my function to AWS with all proper access rights and requirements, etc...</p>
  
  <p>Unfortunately, whenever I test my function in AWS Lambda console, I get the error "Cannot find module 'nodemailer'" which I required in my code below.</p>
  
  <p>From my project structure I seem to have it installed properly, or maybe not. </p>
  
  <p>I've been stuck in this issue for days now, what am I doing wrong here? Btw, I am new to nodejs and aws. </p>
  
  <p>Thank you in advance.</p>
  
  <p><strong>NOTE:</strong> I tried running this in the command and it is working fine, I was able to receive the email.
  command: node handler.js</p>
  
  <p><strong>Project Screenshot:</strong></p>
  
  <p><a href="http://i.stack.imgur.com/R3LS0.png" rel="nofollow">Project Structure</a></p>
  
  <p><strong>Nodejs Code:</strong></p>
  
  <pre><code>'use strict';
  
  var nodemailer = require('nodemailer');
  var transporter = nodemailer.createTransport({
    host: 'email-smtp.us-east-1.amazonaws.com',
    port: 587,
    auth: {
      user: 'USER_XXX',
      pass: 'PASSWORD_XXX'
    }
  });
  
  var text = 'Hi,\r\n\r\n'
       + 'This email is a test email!\r\n\r\n'
       + 'This is sent using NodeMailer module in Nodejs thru AWS SES SMTP Host: email-smtp.us-east-1.amazonaws.com.\r\n\r\n'
       + 'Thanks!';
  
  var mailOptions = {
    from: 'ses@aws.net',
    to: 'me@aws.net',
    subject: 'Test Email (NodeMailer &amp; AWS SES)',
    text: text
  };
  
  module.exports.handler = function(event, context) {
    console.log('Email Sending...');
      transporter.sendMail(mailOptions, function(error, info){
            if(error){
              console.log(error);
            }else{
              console.log('Message sent');
            }
        });
  };
  </code></pre>
  
  <p><strong>Lambda Test Error Message:</strong></p>
  
  <pre><code>{
    "errorMessage": "Cannot find module 'nodemailer'",
    "errorType": "Error",
    "stackTrace": [
      "Function.Module._load (module.js:276:25)",
      "Module.require (module.js:353:17)",
      "require (internal/module.js:12:17)",
      "Object.&lt;anonymous&gt; (/var/task/handler.js:2:18)",
      "Module._compile (module.js:409:26)",
      "Object.Module._extensions..js (module.js:416:10)",
      "Module.load (module.js:343:32)",
      "Function.Module._load (module.js:300:12)",
      "Module.require (module.js:353:17)"
    ]
  }
  </code></pre>