Is there a way to run es6 components, in particular promises and generators, in aws lambda functions

Using ES6 requires the --harmony flag in node v0.12.3.

Is there a way to do this for an aws lambda function?

+5
source share
4 answers

These answers are a bit outdated. AWS announced support for Node.js 4.3.2 in April 2016. 4.3.2 supports ES6. It is also fully backward compatible. More information is available here:

https://aws.amazon.com/blogs/compute/node-js-4-3-2-runtime-now-available-on-lambda/

0
source

You can use babel to convert es6 / es7 for compatibility with node 0.10.x:

http://www.rricard.me/es6/aws/lambda/nodejs/2015/11/29/es6-on-aws-lambda.html

EDIT:

There is also a really cool AWMS lambda deployer called Apex so that you can easily transform and deploy es6 / es7 code! Examples: https://github.com/apex/apex/tree/master/_examples/babel-webpack

EDIT2: There is another AWS deployment module called Gordon , which also helps you integrate lambda with other services, such as:

  • Apigateway
  • CloudWatch Scheduled Events (cron)
  • CloudWatch Events
  • Streams Dynamodb
  • Kinesis Streams
  • S3

They also have many useful examples.

+3
source

AWS Lambda uses v0.10.36 , but anyway I think we can try this way

 var spawn = require("child_process").spawn; var child = spawn('node', [ "--harmony", "es6.js" ], { cwd: __dirname }); 
+1
source

Simple, use bluebird . Any file that requires the use of promises gets the value of bluebird.

 var Promise = require('bluebird'); Promise.aPromise() .then(function () { console.log('ftw!'); }) .catch(function(err) { console.log(err, 'do not forget to catch errors. ever!'); }) 

As for the generators, we are out of luck. bluebird requires a minimum of v0.12+ , and while recording, the lambda is still stuck in node v0.10.36

0
source

All Articles