AWS DynamoDB resource not found exception
Asked Answered
T

9

95

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.

Telemetry answered 22/10, 2016 at 12:42 Comment(2)
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.Equisetum
I just ran into this problem this week too. Rebooting my EC2 instances appears to have resolved it at the moment. Weird...Gamboa
B
115

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

Backhanded answered 23/10, 2016 at 9:53 Comment(8)
I was indeed looking into different region. Fixed it by looking into right region. Thanks!Ranite
For me it was my access key, it was for a different account. Me so stupid. You rock!Decima
I somehow had both the region wrong and had deleted the table last night when trying to re-create it after updating the schema. So double fail on my part...Mastersinger
If you're still having an issue like I was check your JavaScript object instantiation. I had RequestItems: { tableName: item_row }. But I needed to use the table name's directly: RequestItems: { "myTable": item_row }. The issue is that my variable for the tableName was not being accessed. The table name was always tableName in the request which obviously didn't exist.Mastersinger
If you are trying from sls offline make sure you have the env variables set correctly.Boardwalk
I had a problem in the TableName!Cologarithm
Again an incorrect region :(Fractionize
@fIwJlxSzApHEZIl, To use a variable as an object key, put it in brackets, i.e. { [tableName]: item_row }Collude
H
23

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

Hoodoo answered 1/12, 2021 at 22:24 Comment(1)
This is the most detailed and simplest answerCicatrix
M
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.

Mcmann answered 28/10, 2020 at 16:48 Comment(4)
I created the table manually and it worked. It also happens because of creating and removing the table multiple times.Wake
In my case I deleted the ~/.aws/credentials and it started working as before. Thanks for the hint.Flavorous
Same here, I had to change my aws credentials back to different profileNevadanevai
My case was I had right cred for the region but my environment was setting it to a different region.Saucy
T
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:)

Tetzel answered 22/9, 2020 at 15:35 Comment(1)
That solved it for me, or check if you have created the table in the region you want.Jelsma
O
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.
Odie answered 18/4, 2021 at 0:59 Comment(0)
L
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')

Lorielorien answered 18/4, 2021 at 0:44 Comment(1)
I don't think that this answers the person's question. Would you consider writing a comment instead of a solution for your suggestion?Ionize
G
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")
            });
Goidelic answered 6/10, 2021 at 14:45 Comment(0)
I
0

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

Irena answered 24/10, 2023 at 15:15 Comment(0)
R
0

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.

Rosenstein answered 27/4 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.