Getting started with the AWS JS SDK v3 included in the Node runtime

It's time to forget the v2

Author's image
Tamás Sallai
1 min

Bundled SDK

The NodeJs 18 Lamba runtime comes with the usual updates to the language and the standard library. But this time, it also brings one huge improvement: the v3 JS SDK is packaged instead of the old v2.

Starting from Node 18 the v3 SDK is included

Before this release, there was a dilemma: since the v2 was included, it was tempting to use that for simple functions. There is always the option to add a package.json, install the v3 SDK, then use that from the local node_modules. But for a code that spans a few lines only, that process required considerable extra work.

Now that the v3 is bundled, there is no more dilemma: most functions that only interact with AWS services don’t need the npm infrastructure and can be inlined.

Included packages

Since the v3 SDK is modular and it spans hundreds of packages, it’s not obvious which ones are actually installed. Fortunately, the runtime is published as a Docker image and we can inspect it:

docker run --rm -it --entrypoint "npm" --workdir "/var/runtime" amazon/aws-lambda-nodejs:18 ls

At the time of writing, 419 packages were installed in the runtime:


This is a great deal of packages and contains all clients, most utils, and a bunch of ancillary services.

Integrating with AppSync

What I needed was to invoke a mutation in an AppSync API. That includes quite a lot of low-level details related to signing the request. Fortunately, I had everything in the bundle:

import { SignatureV4 } from "@aws-sdk/signature-v4";
import { HttpRequest } from "@aws-sdk/protocol-http";
import { defaultProvider } from "@aws-sdk/credential-provider-node";
import {URL} from "url";
import {Hash} from "@aws-sdk/hash-node";

The @aws-crypo/sha256-js package is not available, but apparently it can be replaced with Hash.bind(null, "sha256"), which is included.

Using these packages, the entirely function code could be inlined:

The function code is inlined in a single file

A single file with all the code and no external dependencies.

29 November 2022
In this article