ResourceNotFoundException: Requested resource not found

0

I'm trying to access DB from one AWS account to another AWS account. I did a STS call and got the AccessID and Key with Session as well. I set the Credentials in DynamoDB object. When i trigger a call with scan, i'm reading an error as

ResourceNotFoundException: Requested resource not found

ResourceNotFoundException: Requested resource not found at Request.extractError (/app/node_modules/aws-sdk/lib/protocol/json.js:51:27) at Request.callListeners (/app/node_modules/aws-sdk/lib/sequential_executor.js:106:20) at Request.emit (/app/node_modules/aws-sdk/lib/sequential_executor.js:78:10) at Request.emit (/app/node_modules/aws-sdk/lib/request.js:688:14) at Request.transition (/app/node_modules/aws-sdk/lib/request.js:22:10) at AcceptorStateMachine.runTo (/app/node_modules/aws-sdk/lib/state_machine.js:14:12) at /app/node_modules/aws-sdk/lib/state_machine.js:26:10 at Request.<anonymous> (/app/node_modules/aws-sdk/lib/request.js:38:9) at Request.<anonymous> (/app/node_modules/aws-sdk/lib/request.js:690:12) at Request.callListeners (/app/node_modules/aws-sdk/lib/sequential_executor.js:116:18)

const AWS = require('aws-sdk');

const roleToAssume = { RoleArn: 'arn:aws:iam::00000000000:role/XXXXXXX-role',
    RoleSessionName: 'session1' };

// Create the STS service object
const sts = new AWS.STS({ apiVersion: '2011-06-15' });

async function getDocumentClient() {
    const data = await sts.assumeRole(roleToAssume).promise();
    const options = { region: 'us-east-1',
        accessKeyId: data.Credentials.AccessKeyId,
        secretAccessKey: data.Credentials.SecretAccessKey,
        sessionToken: data.Credentials.SessionToken };

    AWS.config.update(options);
    if (process.env.DYNAMO_DB_ENDPOINT) {
        return new AWS.DynamoDB.DocumentClient({
            endpoint: process.env.DYNAMO_DB_ENDPOINT
        });
    }
    return new AWS.DynamoDB.DocumentClient();
}

And the other file calls this nodejs file

const Joi = require('@hapi/joi');
const getDocumentClient = require('../util/getDocumentClient');
const verifyApiAccessPermissions = require('../authentication/verifyApiAccessPermissions');

const documentClient = getDocumentClient();

async function scanPrimaryTable(exclusiveStartKey) {
    console.log('===> Into scanPrimaryTable <===');
    // console.log(documentClient);
    const result = await documentClient.scan({
        TableName: process.env.PROXIES_TABLE_NAME,
        Limit: process.env.PAGINATION_LIMIT,
        ExclusiveStartKey: exclusiveStartKey
    }).promise();
    console.log('===> Into Result <===');
    console.log(result);
    return result;
}

async function getProxies(lastEvaluatedKey) {
    const exclusiveStartKey = lastEvaluatedKey ? {
        name: lastEvaluatedKey
    } : undefined;

    return scanPrimaryTable(exclusiveStartKey);
}

async function handler(request, h) {
    const lastEvaluatedKey = request.query.lastEvaluatedKey;
    const result = await getProxies(lastEvaluatedKey);
    const proxies = result.Items;

    const permittedResponse = await verifyApiAccessPermissions(proxies, request.auth.credentials);

    if (result.LastEvaluatedKey) {
        const link = `</proxies?lastEvaluatedKey=${result.LastEvaluatedKey.name}>; rel=next`;
        return h.response(permittedResponse)
            .code(206)
            .header('Link', link);
    }

    return h.response(permittedResponse);
}
  • Can you share some code?

  • You don't call the function but access documentClient. Not clear where do you get it.

2 Antworten
0

I'm using new

return new AWS.DynamoDB.DocumentClient();
beantwortet vor 2 Jahren
  • I see that there are events trails in the destination AWS account where the DynamoDB is present. But not sure why the response is not reciprocated.

0

It sounds like a 'new' might be needed, see if this fixes it: https://github.com/aws/aws-sdk-js/issues/3144

AWS
SeanM
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen