Reputation: 591
I am using the .Net object persistence model to store item into Dynamo DB. It is working fine on my machine, but when I publish the project to AWS lambda service nothing is storing into database.
Please help.
Upvotes: 1
Views: 986
Reputation: 591
I fix the issue by setting "IgnoreValue" to true in DynamoDBContextConfig. Remove the context.SaveAsync(model) from the code. below is the working code sample.
[DynamoDBTable("User")]
public class UserModel
{
[DynamoDBHashKey]
public int ID { get; set; }
[DynamoDBRangeKey]
public string Class { get; set; }
[DynamoDBProperty]
public string Name { get; set; }
}
After initializing above model below is code to insert item into DynamoDB.
public async Task InsertRecord(UserModel model)
{
try
{
using( var context = new DynamoDBContext(client, new DynamoDBContextConfig { ConsistentRead = true, SkipVersionCheck = true,IgnoreNullValues=true }))
{
var dataContext = context.CreateBatchWrite<UserModel>();
dataContext.AddPutItem(model);
await dataContext.ExecuteAsync();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException.StackTrace.ToString());
}
}
Upvotes: 2