title: AWS Lambda Function always returns null (Node/Javascript)?
body: <p>I have a simple Lambda function that is supposed to take event data and send a message to an SNS topic.</p>
  
  <p>Runtime is Node.js 8.10.</p>
  
  <p>Here's my Lambda code in its entirety:</p>
  
  <pre><code>const AWS = require("aws-sdk");
  
  exports.handler = async (event) =&gt; {
  
  const sns = new AWS.SNS();
  
  const emailBody = 
  `
  New Message
  
  From: ${event.name}
  Contact: ${event.contact}
  
  Message: ${event.message}
  `;
  
  const snsMessageParams = {
      TopicArn: process.env.snsTopicArn,
      Message: emailBody
  };
  
  sns.publish(snsMessageParams, (err, data) =&gt; {
      if(err) {
          return err;
      } else {
          return data;
      }
    });
  };
  </code></pre>
  
  <p>Every time I run the function I always get null in response. No error is returned, but I never get a message in my email from SNS, so there is something wrong here. I just can't figure out what.</p>
  
  <p>I am able to successfully publish a message to my SNS topic from the SNS console, and from the Node SDK on my local computer. These work perfectly. I have checked that the snsTopicArn in my env variables is correct by copying and pasting it directly from my successful local code and the SNS console.</p>
  
  <p>I have an Execution Role on my Lambda function that should allow me to publish to SNS on any topic in my account. I chose the default "SNSPublish" option when configuring the role for Lambda just to test everything. But for reference, here is the policy for my Execution Role:</p>
  
  <pre><code>{
    "roleName": &lt;MyRoleName&gt;,
    "policies": [
      {
         "document": {
            "Version": "2012-10-17",
            "Statement": [
              {
                "Effect": "Allow",
                "Action": [
                  "sns:Publish"
                ],
                "Resource": "arn:aws:sns:*:*:*"
              }
            ]
          }
      ...
  }
  </code></pre>
  
  <p>What is going wrong here? Any help is definitely appreciated.</p>