title: MongoAtlas AWS IAM Role Authentication
body: <p>I am setting up a deployment for my company's API Server and it fails to connect to MongoAtlas via IAM role</p>
  <p>What I've done:</p>
  <ol>
  <li>Set up a IAM Role on AWS (APIServer)</li>
  <li>Set up a Database User on Atlas with the role (arn:aws:iam::&lt; my aws acc id &gt;:role/APIServer)</li>
  <li>Configure a launch template and an auto scaling group, launching Amazon Linux EC2 instances with the role</li>
  <li>Have my NodeJS application connect to my Atlas with the following setting:</li>
  </ol>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>key</th>
  <th>value</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>URL</td>
  <td>mongodb+srv://dev.&lt; cluster &gt;.mongodb.net/&lt; DB &gt;</td>
  </tr>
  <tr>
  <td>authSource</td>
  <td>'$external'</td>
  </tr>
  <tr>
  <td>authMechanism</td>
  <td>'MONGODB-AWS'</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I ended up receiving the following error message</p>
  <pre class="lang-sh prettyprint-override"><code>MongoServerError: bad auth : user arn:aws:sts::&lt;my aws acc id&gt;:assumed-role/APIServer/* is not found
  </code></pre>
  <p>Note: the info enclosed in &lt;&gt; are intentionally replaced, since I have already found several solutions pointing out having &lt;&gt; as part of the password, which is not my case here</p>