AWS: Set DynamoDB Table name based on environment

In DynamoDB we can differentiate the tables per environment by prefixing the tables with environment.
e.g. A table "Account" can be created per environment as "Dev_Account", "QA_Account","UAT_Account".

But in the API, we cannot use table names separately for each environment. So, for this situation, we can specify the prefix for the tables globally using the "TableNamePrefix" property on the "DynamoDBContextConfig" object in Startup class under ConfigureServices method as below

var tableNamePrefix = Configuration.GetSection("DynamoDBConfig")["tableNamePrefix"];
if (!string.IsNullOrEmpty(tableNamePrefix))
    AWSConfigsDynamoDB.Context.TableNamePrefix = tableNamePrefix;

Here, we are getting the table prefix from the configuration file and setting the value as dynamodb table prefix globally.


    Blogger Comment
    Facebook Comment


Post a Comment