srandppl
srandppl

Reputation: 571

Amazon DynamoDB InvalidOperationException on AWS

I am trying to do a LoadAsync to Amazon DynamoDB.

        var clientConfig = new AmazonDynamoDBConfig
        {
           
            RegionEndpoint = RegionEndpoint.USEast1
        };
        var client = new AmazonDynamoDBClient(clientConfig);
        var context = new DynamoDBContext(client);            
        return await context.LoadAsync<MyObject>(MyObjectIDString);

When I publish to Beanstalk and call the endpoint, I get an InvalidOperationException:

"Must have one hash key defined for the table MyObject"

The table exists and has values, everything works fine when executed locally from visual studio. I can see the table in the AWS console and get the appropriate objects when i execute locally.

Stacktrace:

   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.MakeKey(Object hashKey, Object rangeKey, ItemStorageConfig storageConfig, DynamoDBFlatConfig flatConfig)\\r\\n   
    at Amazon.DynamoDBv2.DataModel.DynamoDBContext.LoadHelper[T](Object hashKey, Object rangeKey, DynamoDBOperationConfig operationConfig, Boolean isAsync)\\r\\n  
    at Amazon.DynamoDBv2.DataModel.DynamoDBContext.<>c__DisplayClass99_0`1.<LoadAsync>b__0()\\r\\n  

    at Amazon.Runtime.Internal.AsyncRunner.<>c__DisplayClass1_2`1.<Run>b__1()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   
    at Amazon.Runtime.Internal.AsyncRunner.<>c__DisplayClass1_0`1.<<Run>b__0>d.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n 

    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   
    at Eprate.Common.DynamoLayer.DynamoLayer.<GetShow>d__1.MoveNext() in C:\\\\Users\\\\flarp\\\\Source\\\\Repos\\\\EprateGit\\\\Common\\\\DynamoLayer\\\\DynamoLayer.cs:line 38\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n 
       
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   
    at Eprate.API.Controllers.ShowController.<GetShow>d__0.MoveNext() in C:\\\\Users\\\\flarp\\\\Source\\\\Repos\\\\EprateGit\\\\API\\\\Controllers\\\\ShowController.cs:line 24",

Do you have any pointers as to how to investigate this? Do I need to do anything different when deployed on AWS? Something about credentials, or the IAM role maybe?

Upvotes: 1

Views: 4105

Answers (1)

notionquest
notionquest

Reputation: 39226

In the MyObject class, you need to have an attribute for hash key which should be annotated using DynamoDBHashKey annotation.

Also, you need to populate the value of the hash key before calling the load api. Basically, load api is to get the value by key attribute value.

Refer the link for dynamodb annotations.

Upvotes: 4

Related Questions