erradicate

How to fix ResourceNotFoundError in AWS

Technologies
awsdynamodb

Description

You've written the code, deployed the resources, but it isn't working - with a ResourceNotFoundError coming from your Lambda function, EC2 instance, or AWS CLI.

Example

const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
const { DynamoDBDocument } = require('@aws-sdk/lib-dynamodb');

const dynamoDb = DynamoDBDocument.from(new DynamoDBClient({ region: 'us-east-1' }));

const get = async (id) => {
  const item = await dynamoDb.get({
    TableName: process.env.TABLE_NAME,
    Key: { id },
  }); // Requested resource not found
  
  //...
};

Solution

Something about the DynamoDB operation (could be a get, query, scan, put, etc.) is incorrect - it's failing because the name is wrong (typo? missing environment variable?), the table is in a different region than the executing code, or the table was deleted. Double-check the table exists with the correct name in the same region.