Skip to content

DynamoDB OverrideTableName doesn't work #1448

Closed
@vickyRathee

Description

@vickyRathee

I am using Table1 to override using DynamoDBOperationConfig.OverrideTableName but the SDK doesn't override the tableName and throwing error with class name Documents . So the override request not honored and getting error.

Error : Requested resource not found: Table: Documents not found

My requirement is to change the table name dynamically on business logic to insert documents in different tables. So I can't use the [DynamoDBTable("Table1")]

async Task Main()
{
	var document = new Documents {doc_id = "abc", name = "test", created = DateTime.UtcNow};
	
	string tableName = "Table1";
	var dynamo = new DynamoDbService(tableName);
	await dynamo.InsertDocumentAsync<Documents>(document);
	
}

public class DynamoDbService
{
	private static readonly string awsAccessKey = "access key here";
	private static readonly string awsSecretKey = "secret here";
	
	private static DynamoDBOperationConfig _operationConfig;

	private static BasicAWSCredentials awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
	private static AmazonDynamoDBClient client = new AmazonDynamoDBClient(awsCredentials, RegionEndpoint.USEast1);
	private static DynamoDBContext context = new DynamoDBContext(client);

	public DynamoDbService(string tableName)
	{
		_operationConfig = new DynamoDBOperationConfig()
		{
			OverrideTableName = tableName
		};
	}
	
	public async Task InsertDocumentAsync<T>(T document)
	{
		await context.SaveAsync<T>(document);
	}

	public async Task<List<T>> GetDocumentsAsync<T>(string id, int limit = 10)
	{
		QueryFilter filter = new QueryFilter();
		filter.AddCondition("doc_id", QueryOperator.Equal, id);
		QueryOperationConfig queryConfig = new QueryOperationConfig
		{
			Filter = filter,
			Limit = limit,
			BackwardSearch = true
		};
		var documents = await context.FromQueryAsync<T>(queryConfig, _operationConfig).GetNextSetAsync();
		return documents;
	}
}

public class Documents
{
	public string doc_id { get; set; }
	public string name {get; set;}
	public DateTime created {get; set;}
}

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking-changeThis issue requires a breaking change to remediate.bugThis issue is a bug.duplicateThis issue is a duplicate.dynamodb

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions