I am trying to learn how to use AWS’s Comprehend Medical Tool and I am not exactly sure why I am getting this InvalidSignatureException. I am new to using AWS tools for reference. Below is my index.js file and my package.json file. I setup my AWS credentials in a shared file on my computer with the access key and secret access key.
index.js file: Where I create the client and try to access the detectEntities() function from an example text that I got from the Comprehend Medical webpage.
import {S3Client} from "@aws-sdk/client-s3"
import * as AWS from "@aws-sdk/client-s3"
import {ComprehendMedicalClient, DetectEntitiesV2Command} from "@aws-sdk/client-comprehendmedical";
import {fromIni} from "@aws-sdk/credential-providers"
//AWS.config.loadFromPath('./config.json');
// const REGION = "us-east-2";
//const s3Client = new S3Client(config);
const client = new ComprehendMedicalClient({
credentials: fromIni({profile: 'default'}),
region: "us-east-2"
});
const input = {
Text: "Pt is 87 yo woman, highschool teacher with past medical history that includes - status post cardiac catheterization in April 2019. She presents today palpitations and chest pressure. HPI: Sleeping trouble on present dosage of Clonidine. Severe Rash on face and leg, slightly itchy. Meds: Vyvanse 50 mgs po at breakfast daily, Clonidine 0.2 mgs -- 1 and 1 / 2 tabs po qhs. HEENT: Boggy inferior turbinates, No oropharyngeal lesion. Lungs : clear. Heart : Regular rhythm. Skin : Mild erythematous eruption to hairline. Follow-up as scheduled"
};
const command = new DetectEntitiesV2Command(input);
const response = await client.send(command);
console.log(response);
package.json file: where I set the dependencies for the project
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "nodemon index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@aws-sdk/client-comprehendmedical": "^3.349.0",
"@aws-sdk/credential-providers": "^3.350.0",
"@aws-sdk/client-s3": "^3.32.0",
"cors": "^2.8.5",
"express": "^4.18.2",
"mysql2": "^3.3.3",
"nodemon": "^2.0.22"
},
"type": "module"
}
Error Message:
const response = new exceptionCtor({
^
InvalidSignatureException: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
at throwDefaultError (C:UsersshubhOneDriveDesktopProjectsMedical App Exampleservernode_modules@aws-sdksmithy-clientdist-cjsdefault-error-handler.js:8:22)
at C:UsersshubhOneDriveDesktopProjectsMedical App Exampleservernode_modules@aws-sdksmithy-clientdist-cjsdefault-error-handler.js:18:39
at de_DetectEntitiesV2CommandError (C:UsersshubhOneDriveDesktopProjectsMedical App Exampleservernode_modules@aws-sdkclient-comprehendmedicaldist-cjsprotocolsAws_json1_1.js:491:20)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async C:UsersshubhOneDriveDesktopProjectsMedical App Exampleservernode_modules@aws-sdkmiddleware-serdedist-cjsdeserializerMiddleware.js:7:24
at async C:UsersshubhOneDriveDesktopProjectsMedical App Exampleservernode_modules@aws-sdkmiddleware-signingdist-cjsawsAuthMiddleware.js:14:20
at async C:UsersshubhOneDriveDesktopProjectsMedical App Exampleservernode_modules@aws-sdkmiddleware-retrydist-cjsretryMiddleware.js:27:46
at async C:UsersshubhOneDriveDesktopProjectsMedical App Exampleservernode_modules@aws-sdkmiddleware-loggerdist-cjsloggerMiddleware.js:7:26
at async file:///C:/Users/shubh/OneDrive/Desktop/Projects/Medical%20App%20Example/server/index.js:20:18 {
'$fault': 'client',
httpStatusCode: 400,
requestId: '5c6416f9-5c59-4da8-9842-cd4e39bd4886',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
__type: 'InvalidSignatureException'
}
I already looked through the documentation that AWS provides and YouTube videos and I kinda lost on how Comprehend Medical works and how AWS works in general. Any help would be greatly appreciated.
Here are the resources I already looked through:
- https://www.youtube.com/watch?v=gwLtwW1MUTQ&t=1s – unfortunately this video uses v2 of the JavaScript SDK and not v3, so there are some differences in how to implement the client I believe.
- https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/loading-node-credentials-shared.html – this just helped me understand how to setup the shared credentials file and how that works
- https://docs.aws.amazon.com/pdfs/sdk-for-javascript/v3/developer-guide/js-sdk-dg.pdf – tried to implement and understand how other AWS services are used however I got confused.
- https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ComprehendMedical.html – I also looked through this documentation, and I am not sure how to fix the error I am getting using the information given here.