1

I have created a Lambda authentication function in nodeJS and created an API gateway and called the function successfully by passing the parameters from body of the CURL.

Code.

var AWS = require('aws-sdk');
var lambda = new AWS.Lambda();
var RES;
exports.handler = function(event,context,callback) {
    var userName=event.userName;
    var passWord=event.passWord;
  var params = {
    FunctionName: 'ServiceAuthentication', // the lambda function we are going to invoke
    InvocationType: 'RequestResponse',
    LogType: 'Tail',
    Payload: '{ "userName": "'+userName+'","passWord": "'+passWord+'" }'
  };

  lambda.invoke(params, function(err, data) {
    if (err) {
      context.fail(err);

    } else {
      //context.succeed('ServiceAuthentication said '+data.Payload);
      var response=data.Payload;
      console.log("Response received is : ",response);
      if(response === true){
           RES = '{"ResponseJSON":{"Body":{"Datalist":{"Authentication":'+response+'}}}}';
      }else{
           RES = '{"ResponseJSON":{"Body":{"Datalist":{"Authentication":'+response+'}}}}'; 
      }
     callback(null, JSON.parse(RES));
    }});
};

Here in the above code am passing the username and password in the body in CURL request and received successful response

CURL Request:

curl -X POST -d '{"userName": "vikash|214057357158656","passWord": "12345"}' https://execute-api.us-west-2.amazonaws.com/prod/Invokefunction

Response:

{"ResponseJSON":{"Body":{"Datalist":{"Authentication":"true"}}}}

I want to pass the username and password in the header of the curl not in the body.

Ex:

curl -X POST -H "userName": "vikash|214057357158656" -H "passWord": "123456" -d '{}' https://execute-api.us-west-2.amazonaws.com/prod/Invokefunction

But lambda function does not access the header in the curl, how can this be done and how can we successfully pass the header values in the lambda function can any one help..

3
  • 2
    Possible duplicate of stackoverflow.com/questions/31372167/… Commented Jul 19, 2016 at 12:35
  • 1
    Your question is an exact duplicate of stackoverflow.com/questions/31372167/… I suggest using kennbrodhagen's answer to that question. Commented Jul 19, 2016 at 13:04
  • Thanks you @MarkB kennbrodhagen's answer worked for me. Commented Jul 20, 2016 at 5:28

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.