title: DynamoDB BatchGetItem dynamic TableName in Lambda function
body: <p>I'm building a serverless backend for my current application using dynamoDb as my database. I use aws sam to upload my lambda functions to aws. In addition, I pass all my table names as global variables to lambda (nodejs8.10 runtime) to access them on the <code>process.env</code> object within my lambda function. The problem that I'm facing with this is the following: Whenever I run the <code>batchGetItem</code> method on dynamoDB I have to pass a string as my table name, I cannot dynamically change the table name depending on the global variable: </p>
  
  <pre><code>const AWS = require('aws-sdk');
  const dynamodb = new AWS.DynamoDB({region: 'ap-south-1'}, {apiVersion:'2012-08-10'});
  
  const params = {
      RequestItems: {
          //needs to be a string, cannot be a variable containing a string
          'tableName': {
              Keys: [] //array of keys
           }
      }
  }
  dynamodb.batchGetItem(params, (err, result) =&gt; {
  // some logic
  })
  </code></pre>
  
  <p>I need to pass the table name as a string, essentially hardcoding the table name into my function. Other DynamoDB operations, like for example the <code>getItem</code> method, accept a key value pair for the table name in the parameter object: </p>
  
  <pre><code>const tableName = process.env.TableName;
  const getItemParams = {
     Key: {
          "Key": {
               S: 'some key'
           }
     },
     // table name can be changed according to the value past to lambda's environment variable
     TableName: tableName
  }
  dynamodb.getItem(getItemParams, (err, result) =&gt; {
  // some logic
  }
  </code></pre>
  
  <p>Hence my question, is there any way to avoid hardcoding the table name in the <code>batchGetItem</code> method and, instead, allocate it dynamically like in the <code>getItem</code> method? </p>