DEV Community

Teerasak Vichadee
Teerasak Vichadee

Posted on

Save DynamoDB space by use lzutf8

Poor man guide for DynamoDB.

Since DynamoDB has some limitation on space and I want to use a basic data structure and keeps everything in a single document. I'm just a lazy guy, that's it.

So, the best option for me is compress by use lzutf8 on some data that I don't use for search.

compress

compressedByteArray = lzutf8.compress(JSON.stringify(data), {
  outputEncoding: 'ByteArray',
}).toString()
Enter fullscreen mode Exit fullscreen mode

decompress

compressedByteArray = new Uint8Array(
  compressedStringFromDB.split(',').map(i => parseInt(i)), 
  {
    inputEncoding: 'ByteArray',
    outputEncoding: 'String',
  })
Enter fullscreen mode Exit fullscreen mode

How many space I saved? You can try it on your own here.

See ya.

Oldest comments (0)