Trial #21: DynamoDB database not found “Amazon.DynamoDBv2.Model.ResourceNotFoundException”
Problem:
Following a basic AWS SDK for .NET setup as per Matthew Harper ‘s helpful beginner tutorial My program was throwing an “Amazon.DynamoDBv2.Model.ResourceNotFoundException”.
The following line turned out to be at fault blame:
When instantiating the AmazonDynamoDBClient
, if no Region
is passed to the constructor then it defaults to us-west-1
, at least in my case when I tested 10 times in a row. This is not the region I created my DynamoDB instance or the Region
in my profile. So when when I ran the
aws dynamodb list-tables --profile Craig
My table was listed e.g.
Solution:
Tell the AmazonDynamoDBClient
what region your instance is in.
In the constructor using an enum:
In the constructor using your profile value:
In the constructor using a AmazonDynamoDBConfig object. Particularly, its properties RegionEndpoint or ServiceURL if querying a local test instance:
Or preferably, once you have proof of concept, get all your config in a configuration manager. AWS give an example using an app.config file on their code examples page. However, a more complete and appropriate approach is documented in Gary Woodfine’s article “Simple Dependency Injection In AWS Lambda .net core”.
Up-Date: 24/9/2020
I found the following resources from Steve Gordon very helpful when working adding AWS Services to my dependencies container. I will attempt to combine what I have learned in a method or template in a later post.
Leave a comment