Monday, February 17, 2014

Changing your Amazon EBS NodeJS version

By default these days, Amazon's EBS defaults to nodeJS 8.26. Which works great until you add a package that requires a newer version and get a cryptic error message and have to figure it out! In my case I added Bcrypt and it required a newer version of nodeJS. Here is the error I got:

ERROR:
[Instance: i-f39ba2d3 Module: AWSEBAutoScalingGroup ConfigSet: null] Command failed on instance. Return code: 1 Output: Error occurred during build: Command hooks failed .

Clear what that is right?? Well no. So bcrypt requires a newer version. In the management console you can change the version to be the latest amazon supports. I found a news article saying they just rolled out 0.10.21 support, where the latest on the node site is 0.10.25. So just be aware the latest from the nodejs site may not be what amazon supports, they drift a little apart.

Here is how you change the version:

First go here:
Next update this:


DynamoDB write protection with multiple NodeJS apps

To get started, I wanted to figure out exactly how to use DynamoDB. My primary use would be to run several nodejs processes (when my website scales) and have them read and write entries. It's important to know that DynamoDB uses JSON to store objects. As I found out, the REALLY COOL way you can manage write control/locking in DynamoDB is to use conditional put operations. As described in the docs, when you call put, you can specify a condition that must be true for the commit.

For example, say I have a "users logged in" entry with a lastmodified time. Two nodejs apps want to update this entry. So they both read the entry, then they both do a put with the condition of the lastmodified time being what they read initially. One app would succeed and the other would fail, so that app would get the entry again, modify it, and try to commit again.

That's all you need to know to do what essentially boils down to a row lock on the database.