title: AWS Lambda : Unable to import module 'mail': No module named mail
body: <p>I'm following this little tutorial for sending an email when an object is uploaded in a S3 bucket. To use it with Lambda I created a .zip file with following structure:</p>
  
  <p>mail.js
  /node_modules</p>
  
  <p>The mail.js has following code:</p>
  
  <pre><code>var MailComposer = require('mailcomposer').MailComposer,
      mailcomposer = new MailComposer();
  var ses =
      new aws.SES({
          accessKeyId: 'xxxxxxxxxxxx',
          secretAccessKey: 'xxxxxxxxxxxx'});
  
  s3.getObject(params, function(err, data) {
    if (err) {
      //error handling
    } else {
      mailcomposer.setMessageOption({
        from: 'chirer@gmail.com’,
        to: 'sjuif@gmail.com',
        subject: 'Test’,
        body: 's3://' + bucket + '/' + key,
        html: 's3://' + bucket + '/' + key +
              '&amp;lt;br/&amp;gt;&amp;lt;img src="cid:' + key + '" /&amp;gt;'
      });
      var attachment = {
        contents: data.Body,
        contentType: 'image/png',
        cid: key
      };
      mailcomposer.addAttachment(attachment);
      mailcomposer.buildMessage(function(err, messageSource) {
        if (err) {
          // error handling
        } else {
          ses.sendRawEmail({RawMessage: {Data: messageSource}}, function(err, data) {
            if(err) {
              // error handling
            } else {
                context.done(null, data);
            }
          });
        }
      });
    }
  });
  </code></pre>
  
  <p>When I create a lambda function I do the following : </p>
  
  <ol>
  <li>In the select blueprint menu I select "s3-get-object-python"</li>
  <li>I choose my bucket </li>
  <li>As event I choose "Put"</li>
  <li>I click "next"</li>
  <li>I give a name to the lambda function and choose "upload a .zip file"</li>
  <li>I upload the zip file with mail.js and the node_modules directory</li>
  <li>As handler I fill in "mail.handler"</li>
  <li><p>As role I choose "S3 execution role". The wizard gives now a new screen where I click "view policy document". I edit the document, the document is now like:</p>
  
  <pre><code>{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Action": [
          "logs:CreateLogGroup",
          "logs:CreateLogStream",
          "logs:PutLogEvents"
        ],
        "Resource": "arn:aws:logs:*:*:*"
      },
      {
        "Effect": "Allow",
        "Action": [
          "s3:GetObject",
          "s3:PutObject",
          "ses:SendEmail",
          "ses:SendRawEmail"
        ],
        "Resource": [
          "*"
        ]
      }
    ]
  }
  </code></pre></li>
  <li><p>I click 'Allow' and go back to the previous screen</p></li>
  <li><p>Then I choose next en enables the lambda function</p></li>
  </ol>
  
  <p>When I now upload a png file I get the following error in my log.</p>
  
  <pre><code>START RequestId: a4401d96-c0ef-11e5-9ae4-8f38a4f750b6 Version: $LATEST
  **Unable to import module 'mail': No module named mail**
  
  END RequestId: a4401d96-c0ef-11e5-9ae4-8f38a4f750b6
  REPORT RequestId: a4401d96-c0ef-11e5-9ae4-8f38a4f750b6  Duration: 0.35 ms   Billed Duration: 100 ms     Memory Size: 128 MB Max Memory Used: 9 MB   
  </code></pre>
  
  <p>I don't know why because i'm sure the mail.js is in the root of my .Zip file</p>