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:

@aws-sdk
@aws-sdk/abort-controller@3.188.
@aws-sdk/body-checksum-node@3.188.
@aws-sdk/chunked-stream-reader-node@3.188.
@aws-sdk/client-accessanalyzer@3.188.
...
@aws-sdk/client-xray@3.188.
@aws-sdk/cloudfront-signer@3.188.
@aws-sdk/config-resolver@3.188.
@aws-sdk/credential-provider-node@3.188.
...
@aws-sdk/credential-providers@3.188.
@aws-sdk/endpoint-cache@3.188.
@aws-sdk/eventstream-codec@3.188.
...
@aws-sdk/eventstream-serde-universal@3.188.
@aws-sdk/hash-node@3.188.
@aws-sdk/hash-stream-node@3.188.
@aws-sdk/invalid-dependency@3.188.
@aws-sdk/is-array-buffer@3.188.
@aws-sdk/lib-dynamodb@3.188.
@aws-sdk/lib-storage@3.188.
@aws-sdk/md5-js@3.188.
@aws-sdk/middleware-apply-body-checksum@3.188.
...
@aws-sdk/middleware-user-agent@3.188.
@aws-sdk/node_modules
@aws-sdk/node-config-provider@3.188.
@aws-sdk/node-http-handler@3.188.
@aws-sdk/polly-request-presigner@3.188.
@aws-sdk/property-provider@3.188.
@aws-sdk/protocol-http@3.188.
@aws-sdk/querystring-builder@3.188.
@aws-sdk/querystring-parser@3.188.
@aws-sdk/rds-signer@3.188.
@aws-sdk/s3-presigned-post@3.188.
@aws-sdk/s3-request-presigner@3.188.
@aws-sdk/service-client-documentation-generator@3.188.
@aws-sdk/service-error-classification@3.188.
@aws-sdk/sha256-tree-hash@3.188.
@aws-sdk/shared-ini-file-loader@3.188.
@aws-sdk/signature-v4-crt@3.188.
@aws-sdk/signature-v4-multi-region@3.188.
@aws-sdk/signature-v4@3.188.
@aws-sdk/smithy-client@3.188.
@aws-sdk/token-providers@3.188.
@aws-sdk/types@3.188.
@aws-sdk/url-parser@3.188.
@aws-sdk/util-arn-parser@3.188.
...
@aws-sdk/util-waiter@3.188.
@aws-sdk/xhr-http-handler@3.188.
@aws-sdk/xml-builder@3.188.

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.

November 29, 2022

Free PDF guide

Sign up to our newsletter and download the "Foreign key constraints in DynamoDB" guide.


In this article