title: How to access header values in AWS lambda function
body: <p>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.</p>
  
  <p>Code.</p>
  
  <pre><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));
      }});
  };
  </code></pre>
  
  <p>Here in the above code am passing the username and password in the body in CURL request and received successful response </p>
  
  <p>CURL Request:</p>
  
  <pre><code>curl -X POST -d '{"userName": "vikash|214057357158656","passWord": "12345"}' https://execute-api.us-west-2.amazonaws.com/prod/Invokefunction
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>{"ResponseJSON":{"Body":{"Datalist":{"Authentication":"true"}}}}
  </code></pre>
  
  <p>I want to pass the username and password in the header of the curl not in the body.</p>
  
  <p>Ex:</p>
  
  <pre><code>curl -X POST -H "userName": "vikash|214057357158656" -H "passWord": "123456" -d '{}' https://execute-api.us-west-2.amazonaws.com/prod/Invokefunction
  </code></pre>
  
  <p>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..</p>