DEV Community

Enrique Riesgo
Enrique Riesgo

Posted on

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 = "";
}

You have a more elegant

const simpleResult = something?.record?.field || "";

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!

Top comments (0)