DynamoDB
AWS
ResourceNotFoundException
troubleshooting
database management

Simple DynamoDB request failing with ResourceNotFoundException

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Working with AWS DynamoDB, developers may encounter various exceptions, one of which is the ResourceNotFoundException. This exception typically arises during request operations when DynamoDB cannot locate the specified resource, such as a table or index, in the AWS account and region being queried. Understanding why this exception occurs and knowing how to troubleshoot it can enhance efficiency and improve application resilience.

What is a ResourceNotFoundException?

In DynamoDB, a ResourceNotFoundException is thrown when the requested resource does not exist in the context of the account and region being used. It signifies that DynamoDB could not find the table or index referenced in the request. This exception could occur during operations such as GetItem, PutItem, UpdateItem, or DeleteItem.

Common Causes of ResourceNotFoundException

  1. Non-Existent Table or Index: The table or index name specified in the request does not exist.
  2. Incorrect AWS Region: The request is being made to a region where the table or index has not been created.
  3. Typographical Errors: Mistyping of the table or index name in the request parameters.
  4. AWS Account Misalignment: The table or index resides in a different AWS account.
  5. Delay in Resource Creation: After creating a table or index, it might take some time for it to become available.

Troubleshooting ResourceNotFoundException

Addressing this issue requires systematic checks and careful corrections to the query parameters or the AWS infrastructure setup. Here's how you can troubleshoot:

1. Verify Table or Index Existence

Ensure the table or index exists and is active. You can confirm this using the AWS Management Console or AWS CLI:

bash
aws dynamodb describe-table --table-name MyTable

2. Check for Typographical Errors

Review your code for capitalization errors, spelling mistakes, or unintended spaces in table or index names. DynamoDB identifiers are case-sensitive.

3. Validate AWS Region

Ensure your application is connecting to the correct AWS region. Misconfigurations in the region setting can be checked and updated in your application's configuration file.

java
1AmazonDynamoDB client = AmazonDynamoDBClientBuilder
2                        .standard()
3                        .withRegion(Regions.US_EAST_1)
4                        .build();

4. Confirm AWS Account Alignment

Check that you are using the correct AWS account by verifying your account credentials and permissions to access the table or index.

5. Allow Time for Resource Propagation

After creating a table or index, allow some time for it to propagate within AWS infrastructure before performing operations on it.

Example Scenario

Consider a situation where an application intends to retrieve an item from a UsersTable. Here's a simplified example using AWS SDK for Java:

java
1GetItemRequest request = new GetItemRequest()
2    .withTableName("UsersTable")
3    .withKey(Collections.singletonMap("UserId", new AttributeValue("12345")));
4
5try {
6    GetItemResult result = dynamoDBClient.getItem(request);
7    System.out.println("Item: " + result.getItem());
8} catch (ResourceNotFoundException e) {
9    System.err.println("Error: The table or index was not found.");
10}

In this example, if UsersTable does not exist or is not available in the current context, a ResourceNotFoundException will be caught, and an error message will be displayed.

Summary Table

Below is a table summarizing key points regarding ResourceNotFoundException and troubleshooting techniques:

Cause of ExceptionDescriptionActionable Resolution
Non-Existent ResourceResource does not exist in the current context.Ensure table/index exists using AWS CLI/Console.
Typographical ErrorsMisspelling or incorrect capitalization in resource names.Double-check and correct names in code.
Incorrect AWS RegionRequest is made to a wrong region where the resource is absent.Configure the application to access the correct region.
AWS Account MisalignmentResource exists in a different AWS account.Verify and align AWS credentials and permissions.
Delay in Resource PropagationNewly created resources not yet available.Allow some time post-creation for resources to propagate.

Conclusion

The ResourceNotFoundException in DynamoDB can be easily avoided and resolved through careful configuration management and logical review of the API requests. By ensuring your environment is correctly set up, and your requests are validated against existing resources, you can minimize downtime and improve the reliability of your application’s interactions with AWS DynamoDB.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.