vendredi 25 septembre 2015

aws lambda: invoke function via other lambda function

I have a AWS Lambda function, that need's ~ 30 seconds. When I connect it with the API Gateway, it's sending an 504 because of the 5 second timeout. So my easyCron Job is failing and will not try it again (I only have a free plan)

So I need an API, that sends a correct 200 status. My Idea:

Invoke the long term lambda via a short term lamba. The policy is allowing the invokation.

Here is the code

var AWS = require('aws-sdk'),

        params = {
                FunctionName: 'cctv',
                InvocationType: 'RequestResponse',
                LogType: 'Tail'
        },
        lambda;
AWS.config.update({region: 'us-east-1'});
lambda = new AWS.Lambda();

exports.handler = function (event, context) {
        'use strict';
        lambda.invoke(params, function (err, data) {
                if (err) {
                        console.log(err, err.stack);
                }
                else {
                        console.log(data);
                }
        });
        context.succeed('hey cron job, I think my lambda function is not called');

};

But I think, context.succeed() aborts the execution of lambda.invoke()

Do you have any idea how to solve this?




Aucun commentaire:

Enregistrer un commentaire