91

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.

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • 1
    Any chance that you have this problem with Terraform S3 backend? I just ran into the same problem after changing the backen configuriation of Terraform and found out that Terraform is not using the values from the terraform.tf but from the state that is stored in .terraform/terraform.tfstate. – Nils Rommelfanger Aug 29 '18 at 05:38
  • 1
    I just ran into this problem this week too. Rebooting my EC2 instances appears to have resolved it at the moment. Weird... – Dave Splat Aug 30 '18 at 16:13

7 Answers7

113

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

Chen Harel
  • 9,684
  • 5
  • 44
  • 58
19

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.

pmiranda
  • 7,602
  • 14
  • 72
  • 155
19

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. ¯_(ツ)_/¯

Oleg Ushakov
  • 1,200
  • 14
  • 27
7

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:)

RISHU GUPTA
  • 493
  • 6
  • 8
3

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.
1

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')

  • I don't think that this answers the person's question. Would you consider writing a comment instead of a solution for your suggestion? – Yves Gurcan Apr 20 '21 at 14:30
0

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")
            });
Dharman
  • 30,962
  • 25
  • 85
  • 135
Maverick HT
  • 427
  • 5
  • 9