1

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.

1
  • P.S. While using Dynamo DB low level API I am able to store information into Dynamo DB using my AWS Lambda Asp .Net core 2.0 application Commented Jan 26, 2018 at 12:45

1 Answer 1

2

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());
        }

    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.