Upgrading to the AWS SDK for JavaScript v3
Tags: aws, cloud, serverless, javascript
Published: 2021-02-04 16:11:14

---
title: Upgrading to the AWS SDK for JavaScript v3
published: true
date: 2021-02-04 15:12:03 UTC
tags: aws,cloud,serverless,javascript
canonical_url: https://danielleheberling.xyz/blog/new-aws-js-sdk/
---

[![Three Dice](https://danielleheberling.xyz/static/2f94972923899a9a0856ac1409c88745/1c72d/three-dice.jpg "Three Dice")](/static/2f94972923899a9a0856ac1409c88745/b8a7c/three-dice.jpg)

In December 2020, AWS announced [general availability](https://aws.amazon.com/blogs/developer/modular-aws-sdk-for-javascript-is-now-generally-available/) 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](https://aws.amazon.com/blogs/compute/introducing-aws-lambda-extensions-in-preview/). 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](https://github.com/deeheber/note-service/blob/master/README.md) to see the high level architecutre of the app. And [here’s the git diff](https://github.com/deeheber/note-service/pull/4/files) 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](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html) 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](https://github.com/aws/aws-sdk-js-v3/issues/1223) 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](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_util_dynamodb.html). Another example can also be found in my git diff mentioned above.

> Post update March 7, 2021
> Looks like there's now a <a href="https://github.com/aws/aws-sdk-js-v3/pull/2097" target="_blank" rel="noopener noreferrer">DynamoDB Document Client</a> 😀.

## 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!