title: how to dynamically set table name in dynamodb using serverless and DynamoDBContext?
body: <p>We need to be able to set table name based on build environment. Consider the following class:</p>
  
  <pre><code>[DynamoDBTable("movies")]
  public class Movie
  {
      [DynamoDBHashKey]
      public string Title { get; set; }
  
      [DynamoDBRangeKey(AttributeName = "Released")]
      public DateTime ReleaseDate { get; set; }
  
      public List&lt;string&gt; Genres { get; set; }
  }
  </code></pre>
  
  <p>In <code>serverless.yml</code>, can the table name be set like this:</p>
  
  <pre><code>functions:
      update-movies:
          environment:
              tableName: movies-prod
  </code></pre>
  
  <p>Then in the code we can load the table name dynamically based on the table name in the tableName variable. We prefer to use <code>DynamoDBContext</code> rather than <code>DynamoDBv2.DocumentModel</code> (which already has a solution here <a href="https://stackoverflow.com/questions/44043148/how-do-i-dynamically-change-dynamodb-tablename-in-c-sharp-using-object-persisten">How do I dynamically change dynamodb tablename in c# using object persistence model</a>)</p>
  
  <p>Something like this in Java:
  <a href="https://medium.com/@onclouds/aws-lambda-use-different-dynamodb-tables-for-different-stages-5eda9f5378b2" rel="noreferrer">https://medium.com/@onclouds/aws-lambda-use-different-dynamodb-tables-for-different-stages-5eda9f5378b2</a></p>