title: Getting values from parameter store in AWS
body: <p>Here is my code:</p>
  
  <pre><code>const AWS = require('aws-sdk');
  const { Client } = require('pg');
  
  function main() {
      AWS.config.update({region:'eu-west-2'});
  
      let db_user = {
          Name: "postgres_db_user",
          WithDecryption: false
      };
  
      let db_host = {
          Name: "postgres_db_host",
          WithDecryption: false
      };
  
      let db_database = {
          Name: "postgres_db_name",
          WithDecryption: false
      };
  
      let db_password = {
          Name: "postgres_db_password",
          WithDecryption: true
      };
  
      let db_port = {
          Name: "postgres_db_port",
          WithDecryption: false
      };
  
      let database_user_name;
      let database_host;
      let database_name;
      let database_port;
      let database_password;
  
      let ssm = new AWS.SSM();
      ssm.getParameter(db_user, function (err, data) {
          if (err) {
              console.log(err, err.stack);
          } else {
              database_user_name = data;
          }
      });
  
      ssm.getParameter(db_host, function (err, data) {
          if (err) {
              console.log(err, err.stack);
          } else {
              database_host = data;
          }
      });
  
      ssm.getParameter(db_database, function (err, data) {
          if (err) {
              console.log(err, err.stack);
          } else {
              database_name = data;
          }
      });
  
      ssm.getParameter(db_password, function (err, data) {
          if (err) {
              console.log(err, err.stack);
          } else {
              database_password = data;
          }
      });
  
      ssm.getParameter(db_port, function (err, data) {
          if (err) {
              console.log(err, err.stack);
          } else {
             database_port = data;
          }
      });
  
      console.log(database_user_name);
      console.log(database_host);
      console.log(database_name);
      console.log(database_password);
      console.log(database_port);
  
      let client = new Client({
          user: database_user_name,
          host: database_host,
          database: database_name,
          password: database_password,
          port: database_port,
      });
  }
  
  main();
  </code></pre>
  
  <p>The problem is that when I print the variables they are undefined, and I have no idea why. The SSM getParameter function is working because if I use the debugger, I see the values, but it doesn't seem to save the data variable in the variables for some strange reason.</p>
  
  <p>If someone could help me as to why this code is printing undefined for the variables I would appreciate it.</p>