DEV Community

Enrique Riesgo
Enrique Riesgo

Posted on

1 2

What JavaScript features can we use with AWS lambdas

Most of you know that latest version of ECMAScript is 2020, which brought us many very interesting features.

One of the my favourite is optional chaining, a feature that saves us a lot of effort when dealing with multiple nested objects that can be nullish. As per the spec proposal, “an optional chain is a chain of one or more property accesses and function calls, the first of which begins with the token ?.”.

This is, instead of a long and conditional statement like

let result;
if (something && something.record && something.record.field) {
  result = something.record.field;
} else {
  result = "";
}
Enter fullscreen mode Exit fullscreen mode

You have a more elegant

const simpleResult = something?.record?.field || "";
Enter fullscreen mode Exit fullscreen mode

So... ready to start refactoring your old-fashined and chatty AWS lambda code with optional chaining? Stop! 🛑 Have you considered that it is a quite new feature that it may not be supported yet by the lambda AWS running engine?

The question is, how can I know what are the JavaScript features that I can use while developing AWS Lambdas?

The answer is simple and it takes you just a couple of clicks. Let me show you how:

  1. Check what is the NodeJS version you lambdas is running on. You can see that from the AWS console, or in the AWS documentation.
  2. Look at the greate node.green table where you can see the features that you are looking for and its compatibility with your version of NodeJS.

Back to my "optional chain" case, I have seen that my lambdas are running on node 12, and looking at the compatibility table for that feature I have saddly realized that it is not supported 😢. I will have to wait until AWS adds node 14 runtime.

Meanwhile we can keep learning and figuring out how to improve our code.

I hope this helps!

Happy learning and experimentation!

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️