Игорь Голяк
Игорь Голяк

Reputation: 1001

AWS DynamoDB resource not found exception

I have a problem with connection to DynamoDB. I get this exception:

com.amazonaws.services.dynamodb.model.ResourceNotFoundException: Requested resource not found (Service: AmazonDynamoDB; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: ..

But I have a table and region is correct.

Upvotes: 99

Views: 155941

Answers (9)

Stefan
Stefan

Reputation: 806

If the DynamoDB table resides in a different AWS account, reference it by ARN.

When referencing the table by name, it will look up the table in the AWS account of the current IAM user / role / entity etc.

Upvotes: 0

htmlboss
htmlboss

Reputation: 124

My issue was the wrong AmazonDynamoDB client was being injected by Google Guice. The default instance being injected was configured with a different region than the one my table existed in >.>

Upvotes: 0

Oleg Ushakov
Oleg Ushakov

Reputation: 1555

I spent 1 day researching the problem in my project and now I should repay a debt to humanity and reduce the entropy of the universe a little. Usually, this message says that your client can't reach a table in your DB. You should check the next things:

1. Your database is running
2. Your accessKey and secretKey are valid for the database
3. Your DB endpoint is valid and contains correct protocol ("http://" or "https://"), and correct hostname, and correct port
4. Your table was created in the database.
5. Your table was created in the database in the same region that you set as a parameter in credentials. Optional, because some
database environments (e.g. Testcontainers Dynalite) don't have an incorrect value for the region. And any nonempty region value will be correct

In my case problem was that I couldn't save and load data from a table in tests with DynamoDB substituted by Testcontainers and Dynalite. I found out that in our project tables creates by Spring component marked with @Component annotation. And in tests, we are using a global setting for lazy loading components to test, so our component didn't load by default because no one call it in the test explicitly. ¯_(ツ)_/¯

Upvotes: 26

Maverick HT
Maverick HT

Reputation: 547

I was getting this issue in my .NetCore Application. Following fixed the issue for me in Startup class --> ConfigureServices method

        services.AddDefaultAWSOptions(
            new AWSOptions
            {
                Region = RegionEndpoint.GetBySystemName("eu-west-2")
            });

Upvotes: 0

Ravindra Babu Alla
Ravindra Babu Alla

Reputation: 71

Always ensure that you do one of the following:

  1. The right default region is set up in the AWS CLI configuration files on all the servers, development machines that you are working on.
  2. The best choice is to always specify these constants explicitly in a separate class/config in your project. Always import this in code and use it in the boto3 calls. This will provide flexibility if you were to add or change based on the enterprise requirements.

Upvotes: 3

John Christian
John Christian

Reputation: 85

If your resources are like mine and all over the place, you can define the region_name when you're creating the resource.

I do this for all my instantiations as it forces me to think about what I'm putting/calling where.

boto3.resource("dynamodb", region_name='us-east-2')

Upvotes: 1

pmiranda
pmiranda

Reputation: 8470

My problem was stupid but maybe someone has the same... I changed recently the default credentials of aws (~/.aws/credentials), I was testing in another account and forgot to rollback the values to the regular account.

Upvotes: 20

RISHU GUPTA
RISHU GUPTA

Reputation: 563

If DynamoDB table is in a different region, make sure to set it before initialising the DynamoDB by

AWS.config.update({region: "your-dynamoDB-region" });

This works for me:)

Upvotes: 8

Chen Harel
Chen Harel

Reputation: 10062

From the docs it's either you don't have a Table with that name or it is in CREATING status.

I would double check to verify that the table does in fact exist, in the correct region, and you're using an access key that can reach it

Upvotes: 122

Related Questions