Lambda Node 20

With Node 20 becoming LTS around the corner, has anyone seen anything about Node 20 on an official Lambda run time or does it look like we’ll have to revert to building our own runtime if we want Node 20?

Always refer to https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

They will probably support it at some point, but currently I would stay with version 18. If you depend on node 20 you should maybe invest in a custom runtime for now.

Of course. Wondering if people have seen anything about it mainly because we’re running a mix of 14, 16 and 18. While I’m updating all to 18 it’s probably a time saver to move to 20 even if that’s a delay while we wait for the run time.

As a rough estimate you could take a look at the initial release of node 18 which was on 2022-04-19 and it’s activation as LTS 2022-10-25. Amazon started support for node 18 on 2022-11-18.

Sources:
https://nodejs.dev/en/about/releases/
https://aws.amazon.com/de/about-aws/whats-new/2022/11/aws-lambda-support-node-js-18/

So getting support in november or december would be a good guess in my opinion. Nonetheless node 14 will run out of support on 2023-11-27 so from an enterprise standpoint it would be safer to switch to node 18 beforehand. I also have to switch a few lambdas from node 14 up and I will try the following:

  • Take a look if a switch to node 18 will just work
  • If node 18 is not working try the same with node 16
  • If node 16 is just working stay with that until node 20 is released
  • If you have to spend work on it anyway just go to node 18

I will try it that way because aws also switches aws-sdk from 2 to 3 when going from node 16 to node 18. My intuition tells me that this could be the real culprit and that one also should start adopting aws-sdk which will be some extra work.

I will probably start switching versions in late september, because I got a lot of other work in the pipeline. It would be kind of you, if you could share your experience of switching if you try it out soon.

I suspect they’re trying to get al2023 based runtimes going. The fact they were able to deliver 18 on al2 took a bit of a hack to update glibc to >= 2.28

You need to support that ticket
https://github.com/aws/aws-codebuild-docker-images/issues/631

Lambda using same images

It should be available shortly after 20 becomes LTS, on or about 2023-10-24. Putting available info from sources and comments together, I’d expect it to be about 2 or 3 weeks after LTS, except I guess that 18 had extra obstacles to being available, so 20 may be sooner.

And I am eagerly awaiting 20 being available since it introduces a native method of parsing form data, complete with support for File objects. I’m already working on a class to publish on npm that extends Request:

constructor({
	httpMethod,
	body,
	path = '/',
	rawQuery,
	isBase64Encoded = false,
	headers: { referer, cookie, ...headers } = {},
}) {
	const url = new URL(`${path || '/'}`,
		process.env.BASE_URL ?? headers.hasOwnProperty('host')
			? `http://${headers.host}`
			: 'http://localhost:9999'
	);

if (typeof rawQuery === 'string' && rawQuery.length !== 0) {
		url.search = rawQuery;
	}

super(url, {
		method: httpMethod,
		mode: headers['sec-fetch-mode'],
		headers: new Headers(headers),
		referrer: referer, // Deal with typo in HTTP spec
		body: (
			typeof body === 'string'
			&& ! ['GET', 'DELETE', 'HEAD', 'OPTIONS'].includes(httpMethod)
		)
			? isBase64Encoded ? atob(body) : body
			: undefined,
	});

// Parse and store cookies in a private Map
	if (typeof cookie === 'string' && cookie.length !== 0) {
		this.#cookies = new Map(cookie.split(';').map(c => c.split('=').map(s => decodeURIComponent(s.trim()))));
	} else {
		this.#cookies = new Map();
	}
}

The class possibly being a bit more oriented towards Netlify Functions. Not sure about getting the BASE_URL environment var and if that is a Netlify or AWS thing. Don’t think it really makes much difference though.