Using the async keyword in AWS Lambda

I play with AWS Lambda using Node.js. After you got tired of calling callbacks, I decided that I could elegantly use async/awaitit just like I was used to C #.

exports.handler = async(event, context, callback) => {
    db = await MongoClient.connect(process.env['MONGODB_URI']);
}

Although this seems to work when testing offline using lambda-local, it loads with an error in AWS. It seems that the keyword is asyncnot recognized. I am using the latest version of Node.js 6.10 on AWS, while my local version is 8.5. Is there a way, or should I abandon this approach and return to using callbacks?

+4
source share
4 answers

async/await Node.js v7.0, --harmony, . Node.js v7.6.

, async/await Node.js v6.10.

, , .

+5

webpack babel, node 8 node 6 .

- serverless framework , :

+4

Typescript, ES5.

async/await Typescript.

+2

Node.js v8.10 runtime is available in AWS Lambda as of April 2, 2018. Follow the link below for more information:

https://aws.amazon.com/blogs/compute/node-js-8-10-runtime-now-available-in-aws-lambda/

+1
source

Source: https://habr.com/ru/post/1687352/


All Articles