title: Decrypting multiple env. variables in AWS Lambda
body: <p>I've got a number of encrypted environmental variables I need to decrypt in an AWS Lambda function. They give an example bit of code, but I'd rather not run a huge chunk for each value I need to decrypt: </p>
  
  <pre><code>const AWS = require('aws-sdk');
  
  const encrypted = process.env['my_password'];
  let decrypted;
  
  
  function processEvent(event, context, callback) {
      // TODO handle the event here
  }
  
  exports.handler = (event, context, callback) =&gt; {
      if (decrypted) {
          processEvent(event, context, callback);
      } else {
          // Decrypt code should run once and variables stored outside of the function
          // handler so that these are decrypted once per container
          const kms = new AWS.KMS();
          kms.decrypt({ CiphertextBlob: new Buffer(encrypted, 'base64') }, (err, data) =&gt; {
              if (err) {
                  console.log('Decrypt error:', err);
                  return callback(err);
              }
              decrypted = data.Plaintext.toString('ascii');
              processEvent(event, context, callback);
          });
      }
  };
  </code></pre>
  
  <p>I'm wondering if the AWS SDK includes a function that lets me decrypt multiple values at once. Failing that, is there a way to elegantly chain these calls together so they don't take up ~75 lines of my otherwise simple function?</p>