title: Safe way to generate unique primary keys from AWS Lambda functions with Node.js
body: <p>I am using AWS Lambda with Node.js to insert items to my DynamoDB tables and need to generate unique ids for the items.</p>
  
  <p>My biggest concern is with entropy in AWS Lambda underlying infrastructure, and risk of collisions with high number of ids per second.</p>
  
  <p>I am using nanoid, but not sure if it meet this requirements. The code that I am using is this:</p>
  
  <pre><code>const { customAlphabet } = require("nanoid");
  const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  const idSize = 20;
  const nanoid = customAlphabet(alphabet, idSize);
  const id = nanoid(); //=&gt; "scLV4Vc7OrJ2Vpib9rz6"
  </code></pre>
  
  <p>How does nonoid generates randomness? Is it safe to use in AWS Lambda functions (high entropy and low change of collisions)? If not, what are the alternatives?</p>