title: AWS Lambda HTTPS Request - Blueprint
body: <p>I am bit new to AWS LAmbda and am trying to make an http request to a server through AWS Lambda function. I have used AWS HTTPS blueprint code and made only modification in <code>option</code> variable (see the code below).</p>
  
  <pre><code>const https = require('https');
  
  let headers = {
      'Authorization': 'ApiKey {key}'
  };
  
  let options = {
      url: 'https://myds.io/api/external/patients/events/medications/',
      headers: headers
  };
  
  exports.handler = (event, context, callback) =&gt; {
      const req = https.request(options, (res) =&gt; {
          let body = '';
          console.log('Status:', res.statusCode);
          console.log('Headers:', JSON.stringify(res.headers));
          res.setEncoding('utf8');
          res.on('data', (chunk) =&gt; body += chunk);
          res.on('end', () =&gt; {
              console.log('Successfully processed HTTPS response');
              // If we know it's JSON, parse it
              if (res.headers['content-type'] === 'application/json') {
                  body = JSON.parse(body);
              }
              callback(null, body);
          });
      });
      req.on('error', callback);
      req.write(JSON.stringify(event.data));
      req.end();
  };
  </code></pre>
  
  <p>When I am trying to run this code, I am getting the following error. I am not able to understand, where is the problem and what is wrong with the syntax. Request you to help me. </p>
  
  <p><a href="https://i.stack.imgur.com/inr2F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/inr2F.png" alt="enter image description here"></a></p>
  
  <p>Just to invoke this Lambda function. I am using the following test function.</p>
  
  <p><a href="https://i.stack.imgur.com/TInXT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TInXT.png" alt="enter image description here"></a></p>
  
  <p>The following is the execution result.</p>
  
  <pre><code>Response:
  {
    "errorMessage": "connect ECONNREFUSED 127.0.0.1:443",
    "errorType": "Error",
    "stackTrace": [
      "Object._errnoException (util.js:1022:11)",
      "_exceptionWithHostPort (util.js:1044:20)",
      "TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)"
    ]
  }
  
  Request ID:
  "0fae1df6-6351-11e8-9741-a3dc748f359b"
  
  Function Logs:
  START RequestId: 0fae1df6-6351-11e8-9741-a3dc748f359b Version: $LATEST
  2018-05-29T15:00:44.205Z    0fae1df6-6351-11e8-9741-a3dc748f359b    {"errorMessage":"connect ECONNREFUSED 127.0.0.1:443","errorType":"Error","stackTrace":["Object._errnoException (util.js:1022:11)","_exceptionWithHostPort (util.js:1044:20)","TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)"]}
  END RequestId: 0fae1df6-6351-11e8-9741-a3dc748f359b
  REPORT RequestId: 0fae1df6-6351-11e8-9741-a3dc748f359b  Duration: 35.27 ms  Billed Duration: 100 ms     Memory Size: 128 MB Max Memory Used: 22 MB  
  </code></pre>