title: Pass AWS config to imported module
body: <p>I am trying to unit test a JS AWS Lambda by running it locally. To emulate the Lambda environment I am assuming the same role as the Lambda would have with AWS.config.credentials and then simply calling the Lambda function that I imported with require.</p>
  
  <p>This works if I copy and paste the Lambda function to the test file but if I import it then it seems the function runs with a clean AWS.config which doesn't have my configuration. I could change the way the Lambda module imports AWS (make it global or do something else) in order to get the config from the test but I would prefer to keep the file exactly as it should be for uploading to Lambda. </p>
  
  <p>In AWS Lambda the AWS credentials are somehow preconfigured without the module having to do anything and I would like to emulate that functionality. How can this be done in Node?</p>
  
  <p>EDIT:
  You can run any example function in AWS Lambda. For example just the following code simply works when run in proper AWS Lambda.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var AWS = require("aws-sdk");
  var dynamo = new AWS.DynamoDB.DocumentClient();
  dynamo.query(...)</code></pre>
  </div>
  </div>
  </p>
  
  <p>To run this locally you have to precede this code with the following:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>AWS.config.update({region: 'us-east-1'}); 
  AWS.config.credentials = new AWS.SharedIniFileCredentials();
  AWS.config.credentials = new AWS.TemporaryCredentials({
    RoleArn: 'arn:aws:iam::1234567890:role/TemporaryCredentials',
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>The problem is that running this config step in the unit test file does not make the config available to an imported lambda function and does therefore not emulate the environment properly.</p>