Upgrading to the AWS SDK for JavaScript v3

Danielle Heberling - Feb 4 '21 - - Dev Community

Three Dice

In December 2020, AWS announced general availability of version 3 of their SDK for JavaScript. I decided to take some time to experiment and see what’s changed.

What’s New?

There are lots of new features in this release. Here’s the new features that I’ve seen highlighted the most.

Modular Packages

In prior versions, we’d just npm install the entire aws-sdk package and everything was in there. Now the sdk is split among multiple npm packages. Just install the packages that you need to use for your application. This is a big win for being able to get those code bundle sizes down.

Middleware Stack

The Middleware Stack gives developers more control over the lifecycle of the requests sent via the aws-sdk. My internal mental reaction is similar to how I felt after hearing the AWS Lambda Extensions announcement. It seems interesting, but I’m not quite sure what I’d do with it. That doesn’t mean this isn’t an exciting feature to someone else.

First Class TypeScript Support

TypeScript is growing in popularity, so it seems fitting that AWS would continue the trend. As someone who recently started using TypeScript, this is pretty exciting.

Let’s See Some Code!

Because I was curious about how everything might look in v3, I experimented by converting a minimally featured CRUD api to use the new version. Check out the README to see the high level architecutre of the app. And here’s the git diff when converting from the sdk v2 to v3.

Since DynamoDB is my database in this app, I went looking for the v3 equivalent of the DynamoDB document client that strips out the DynamoDB types and makes things more human readible. I found some mixed messaging on the official AWS Github repo for the JavaScript SDK and my overall takeway is that originally an AWS employee said they’d port it over, now it looks like that probably won’t happen. My personal opinion is that they could’ve done a better job communicating in this issue filed on Github.

Anyway long story short, I found I was able to get the same result by marshalling and unmarshalling JavaScript objects/DynamoDB Records in the code. Info on that can be found in the docs for the util-dynamodb package here. Another example can also be found in my git diff mentioned above.

Post update March 7, 2021
Looks like there's now a DynamoDB Document Client 😀.

What’s Next?

Out of caution, I plan to wait for things to settle a bit more before doing upgrades on major business critical applications.

This has been a fun experiment to see what’s changed, what stayed the same, and what I can look forward to in the future. Overall, I felt like AWS did a great job with this rewrite.

What are your thoughts on the update? Have any fun use case ideas with the new middleware stack feature? Let me know!

. . . . . . . . . . . . . . . . . . . . . . . . . . . .