title: AWS SDK - Writing a lambda to get all roles for the current account
body: <p>Working on writing a lambda to get all IAM roles within the current account using the AWS SDK documentation provided for Javascript: <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IAM.html</a></p>
  <p>However, my lambda keeps returning a null value, whereas I'm expecting it to return a list of existing roles in the response body:</p>
  <pre><code>const AWS = require(&quot;aws-sdk&quot;);
  
  exports.handler = async (event) =&gt; {
      var iam = new AWS.IAM();
  
      var roles = [];
      iam.listRoles(function(err, data) {
          if (err) console.log(err, err.stack); // an error occurred
          else roles.push(data);           // successful response
          const response = {
            statusCode: 200,
            body: JSON.stringify(roles)
        };
        return response;
      });
   
  };
  </code></pre>
  <p>I'm obviously missing something here. Any insights would be appreciated.</p>