1
votes

I am a newbie to both Alexa & Nodejs.

I am writing a new AWS lambda function based on sample nodejs color alexa skillset lets say MySchedule which will be invoked by Alexa.

I am trying to call another AWS lambda function MyTravelPlans from MySchedule lambda function.

Can anyone please let me know how this possible - 1. Do I need multiple handlers? If yes , how do i make the call. 2. Can i call the MyTravelPlans lambda function without writing a handler ? If yes any example to make sure invoke method is not done asynchronosly

1

1 Answers

0
votes

Assuming that both lambdas have the same role, you can call one lambda from another using the aws-sdk.

var aws = require('aws-sdk');
aws.config.region = 'us-east-1'; //or whatever your region
var lambda = new aws.Lambda();

  var params = {
    FunctionName: 'MyTravelPlans' //name of lambda
    InvocationType: 'RequestResponse', //Event | RequestResponse | DryRun
    Payload: '{ "data" : "hello" }'
  };

  lambda.invoke(params, function(err, data) {
    if (err) {
      context.fail(err);
    } else {
      context.succeed('response from My Travel Plans '+ data.Payload);
    }
  })

The thing that you need to make sure of is that you have all the appropriate policies attached to your role (in the IAM management console). Finally, as a side note, I know you are asking specifically for a synchronous operation but a popular alternative for lambda-to-lambda communication is to use sns