5

ES6 usage requires --harmony flag in node v0.12.3.

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

Yves M.
  • 29,855
  • 23
  • 108
  • 144
Swaraj Giri
  • 4,007
  • 2
  • 27
  • 44

4 Answers4

3

You can use babel to transform es6/es7 to be compatible 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 AWS lambda deployer called Apex with that you can transform and deploy es6/es7 code easily! Examples: https://github.com/apex/apex/tree/master/_examples/babel-webpack

EDIT2: There is an other AWS lambda deployer called Gordon which also helps you integrate lambda with other services such as:

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

They also have a lot of useful examples

barczag
  • 741
  • 6
  • 10
1

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

var spawn = require("child_process").spawn;
var child = spawn('node', [ "--harmony", "es6.js" ], {
  cwd: __dirname
});
zhiyelee
  • 429
  • 4
  • 14
0

Simple, use bluebird . Any file that requires to make use of promises, get bluebird in scope.

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 far as generators are concerned, we are out of luck. bluebird requires minimum v0.12+ and at the time of writing lambda is still stuck in node v0.10.36

Swaraj Giri
  • 4,007
  • 2
  • 27
  • 44
0

These answers are a bit out of date. AWS announced support for Node.js 4.3.2 runtime in April 2016. 4.3.2 supports ES6. It is also completely backwards compatible. More details available here:

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

thun
  • 478
  • 3
  • 12