Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printf Statement not working on lambda

I tried to create a lambda function using node.js. w wrote code in C code and convert it to node library using node-gyp. lambda function perfectly working. but it print only node.js console.log statements.

This is my node.js code

'use strict';
console.log('Loading function');

exports.handler = (event, context, callback) => {

var addon = require('./build/Release/testLibraryfromCcode');

addon.sayHello();
console.log("Completed");
}

This is my C code

int sayHello()
{
    printf("Haaaaaaaaaaaaai\n");
    fflush(stdout);
    return 0;   
}

I got output like this from lambda test console

   TART RequestId: 3e8cd5ff-2d41-11e6-af8f-ada8f1249113 Version: $LATEST
    2016-06-08T06:21:32.779Z    3e8cd5ff-2d41-11e6-af8f-ada8f1249113    Loading function
   2016-06-08T06:21:32.779Z 3e8cd5ff-2d41-11e6-af8f-ada8f1249113 Completed

Haaaaai print is missing. i need to print printf statements in my C code. if any idea?

like image 833
Abdul Manaf Avatar asked Jun 08 '16 06:06

Abdul Manaf


1 Answers

This code is working. fflush(stdout) is enogh for printing.

int sayHello()
{
    printf("Haaaaaaaaaaaaai\n");
    fflush(stdout);
    return 0;   
}

But, aws lamda cannot print library prints directly on web console. We need to install awslogs for waching full logs.

  1. install awslogs

    sudo pip install awslogs

  2. for Waching logs.

    awslogs get /aws/lambda/lambdaFunctionName --start="3h"

like image 147
Abdul Manaf Avatar answered Nov 05 '22 01:11

Abdul Manaf