title: How to access the aws parameter store from a lambda using node.js and aws-sdk
body: <p>I've created a lambda and cloud formation template which grants a lambda access to the parameter store and secrets manager. When I test the lambda I have the following functions outside of the export.handler function:</p>
  
  <pre><code>function getParameterFromStore(param){
      let promise = new Promise(function(resolve, reject){
          console.log('++ ' + param.Path);
          servmgr.getParametersByPath(param, function(err, data){
              if(err){
                  reject(console.log('Error getting parameter: ' + err, err.stack));
              } else {
                  resolve(data);
              }
          });
      });
  
     let parameterResult = promise.then(function(result){
      console.log('---- result: '+ JSON.stringify(result));
          return result;
      });
     return parameterResult;
  };
  </code></pre>
  
  <p><code>servmgr</code> is instantiated as <code>var servmgr = new AWS.SSM();</code></p>
  
  <p>When I call this function from the export.handler function I do so as:</p>
  
  <pre><code>myFirstParam =  { Path : '/myPath/Service/servicesEndpoint'};
  
  let endpointResult = getParameterFromStore(myFirstParam);
  </code></pre>
  
  <p>In the lambda I have the function retrieve the parameter defined outside of the export.handler function bt wrapped in a promise.</p>
  
  <p>When I run/test this lambda the object returned is always undefined... I get Parameters[] back but no values.</p>
  
  <pre><code>2019-02-20T21:42:41.340Z    2684fe88-d552-4560-a477-6761f2de6717    ++ /myPath/Service/serviceEndpoint
  2019-02-20T21:42:41.452Z    2684fe88-d552-4560-a477-6761f2de6717    ---- result: {"Parameters":[]}
  </code></pre>
  
  <p>How do you get parameter values returned back to a lambda at run time?  </p>
  
  <p><strong>update</strong></p>
  
  <p>based upon the suggestion/answer from Thales I've simplified the lambda to just this:</p>
  
  <pre><code>const getParameterFromStoreAsync = (param) =&gt; {
      return new Promise((resolve, reject) =&gt; {
          servmgr.getParametersByPath(param, (err, data) =&gt; {
              if(err){
                  reject(console.log('Error getting parameter: ' + err, err.stack));
              } 
              return resolve(data);
          });
      });
  };
  
  exports.handler = async(event, ctx, callback) =&gt; {
  
  console.log('INFO[lambda]: Event: [' + JSON.stringify(event, null, 2) + ']');
  
      console.log('this is the event' + JSON.stringify(event));
      sfdcEndPointParam =  { Path : '/PartnerBanking/Service/SfdcEndpoint'};
      let myendpoint = await getParameterFromStoreAsync(sfdcEndPointParam);
  
      console.log('### endpoint path: ' + JSON.stringify(myendpoint));
  
  done = ()=&gt;{}
  callback(null, done());
  };
  </code></pre>
  
  <p>I am still seeing an empty array being returned in my tests:</p>
  
  <pre><code>### endpoint path: {"Parameters":[]}
  </code></pre>
  
  <p>I've also moved the function into the callback as</p>
  
  <pre><code>exports.handler = (event,ctx, callback){
  done = async()=&gt;{
   console.log('this is the event' + JSON.stringify(event));
      sfdcEndPointParam =  { Path : '/PartnerBanking/Service/SfdcEndpoint'};
      let myendpoint = await getParameterFromStoreAsync(sfdcEndPointParam);
  
      console.log('### endpoint path: ' + JSON.stringify(myendpoint));}
  }
  callback(null, done());
  </code></pre>
  
  <p>Same result ... empty array.  Any additional things to try?</p>