title: How to deal with limit size when reached at AWS DynamoDB?
body: <p>We're trying to take huge advantage of <em>AWS</em>'s <strong>DynamoDB</strong>'s <strong><em>NoSQL</em></strong> with <strong><em>IoT</em></strong> stuff, but we're not sure of what best practices are regarding item length or item insertions.</p>
  
  <p>Flow goes, each device can read environment data, depending on type of data captured, device sends that <em>"event's"</em> <code>JSON</code> message to <strong>IoT</strong> <em>broker</em>, then to a <strong>Lambda</strong> function in order to map that payload, process it and write to <strong>DynamoDB</strong> table.</p>
  
  <p>Then, there's one table per type of event captured, and an item for each event message received from devices.
  But we've come to realize that that's just another pseudo-relational approach.</p>
  
  <p>Read the docs, and thought about only one table as best practice, and one item per device growing in it's inside, with an array of those <code>JSON</code> events classified by the key's name.</p>
  
  <p>Something like:</p>
  
  <pre><code>    {
          "partition":"&lt;str_an_id&gt;"",
          "range":&lt;uint_maybe_a_timestamp&gt;,
          "event_soil":[
              {&lt;&lt;object with variable length #0},
              {&lt;&lt;object with variable length #1}
              ...
              {&lt;&lt;object with variable length #n}
          ],
          "event_humidity":[
              {&lt;&lt;object with variable length #0},
              {&lt;&lt;object with variable length #1}
              ...
              {&lt;&lt;object with variable length #n}
          ],
          "event_light":[
              {&lt;&lt;object with variable length #0},
              {&lt;&lt;object with variable length #1}
              ...
              {&lt;&lt;object with variable length #n}
          ],
          "event_temperature":[
              {&lt;&lt;object with variable length #0},
              {&lt;&lt;object with variable length #1}
              ...
              {&lt;&lt;object with variable length #n}
          ]
      }
  </code></pre>
  
  <p>Currently we have two devices, so we're expecting to have two items growing with the <code>JSON</code> payload from devices. But, at some point, memory threshold is reached, and a <code>400</code> error code from <strong>DynamoDB</strong> raises.</p>
  
  <p>Is this approach right? Or totally wrong? </p>
  
  <p>Is there any approach for knowing when to reach that limit?  Like, some sort of pagination or something?</p>
  
  <p>It's hard to bring the math of calculating item size because the <code>JSON</code> objects currently vary in length, and may vary in the future.</p>
  
  <p>Also we've come to think about creating items each one or two months (theoretically since we accelerate devices) per device. But, not sure.</p>