Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batchGet method not working #107

Open
vijay9561 opened this issue Jul 11, 2023 · 2 comments
Open

batchGet method not working #107

vijay9561 opened this issue Jul 11, 2023 · 2 comments
Labels
help wanted We are welcoming your contribution :) needs triage The issue is open and it needs proper triaging

Comments

@vijay9561
Copy link

Hi Team,
I have trying to get batch of record. But I'm unable to fetch the record and getting the below error and code.
Please help on that issue.

My Below code
import AWS, { DynamoDB } from 'aws-sdk';
const docClient = new AWS.DynamoDB.DocumentClient();

    const keyMap = await custIDs.map((element: any) => {
        return { customerId: element.mergeCustId.toString(), vehicleId: element.mergeCustId.toString() };
    });
    console.log("keyMap", JSON.stringify(keyMap));
    const params = {
        RequestItems: {
            'eos-dev-Customer-Vehicles': {
                Key: keyMap,
            }
        }
    };
    console.log("params", JSON.stringify(params));
    return docClient.batchGet(keyMap, (err: any, data: any) => {
        if (err) {
            console.log("err", err);
        } else { console.log("data", data); }
    });

Error:

2023-07-11T10:39:32.993Z a89ddd1c-c372-468c-a9d2-a91173ab9a82 INFO err MissingRequiredParameter: Missing required key 'RequestItems' in params
at ParamValidator.fail (/var/task/output/purge-merge-automation/index.js:22005:37)
at ParamValidator.validateStructure (/var/task/output/purge-merge-automation/index.js:22016:14)
at ParamValidator.validateMember (/var/task/output/purge-merge-automation/index.js:22043:21)
at ParamValidator.validate (/var/task/output/purge-merge-automation/index.js:21989:10)
at Request.VALIDATE_PARAMETERS (/var/task/output/purge-merge-automation/index.js:19767:42)
at Request.callListeners (/var/task/output/purge-merge-automation/index.js:25757:20)
at callNextListener (/var/task/output/purge-merge-automation/index.js:25747:12)
at /var/task/output/purge-merge-automation/index.js:19721:9
at finish (/var/task/output/purge-merge-automation/index.js:14369:7)
at /var/task/output/purge-merge-automation/index.js:14387:9
at EnvironmentCredentials.get (/var/task/output/purge-merge-automation/index.js:14925:7)
at getAsyncCredentials (/var/task/output/purge-merge-automation/index.js:14381:24)
at Config.getCredentials (/var/task/output/purge-merge-automation/index.js:14401:9)
at Request.VALIDATE_CREDENTIALS (/var/task/output/purge-merge-automation/index.js:19716:26)
at Request.callListeners (/var/task/output/purge-merge-automation/index.js:25753:18)
at Request.emit (/var/task/output/purge-merge-automation/index.js:25729:10) {
code: 'MissingRequiredParameter',
time: 2023-07-11T10:39:32.990Z
}

@tebanieo
Copy link
Contributor

tebanieo commented Jul 11, 2023

I am going to assume you have properly set up your credentials in your AWS environment and that you have imported the right AWS SDK libraries. At first glance, I can see you have a typo on your params const, it should include the word Keys not Key:

const params = {
        RequestItems: {
            'eos-dev-Customer-Vehicles': {
                Keys: keyMap,
            }
        }
    };

In your example, you are not sending params to the batch get item operation, you are sending keyMap and that JSON does not have the required parameters. I suggest you fix the typo and send the right variable to the batchGet method and let me know the results.

@vijay9561
Copy link
Author

After Adding the Keys instead of key. But still getting the same error

const keyMap = await custIDs.map((element: any) => {
return { customerId: element.mergeCustId.toString(), vehicleId: element.mergeCustId.toString() };
});
console.log("keyMap", JSON.stringify(keyMap));
const params = {
RequestItems: {
'eos-dev-Customer-Vehicles': {
Keys: keyMap,
}
}
};
console.log("params", JSON.stringify(params));
return docClient.batchGet(keyMap, (err: any, data: any) => {
if (err) {
console.log("err", err);
} else { console.log("data", data); }
});

@tebanieo tebanieo added the needs triage The issue is open and it needs proper triaging label Jan 30, 2024
@tebanieo tebanieo added the help wanted We are welcoming your contribution :) label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We are welcoming your contribution :) needs triage The issue is open and it needs proper triaging
Projects
None yet
Development

No branches or pull requests

2 participants