Hi,
If I try to construct the ComprehendMedical service using the current npm package, I receive the following error:
TypeError: aws_sdk__WEBPACK_IMPORTED_MODULE_4__.ComprehendMedical is not a constructor
I attempted to look for comprehend medical and found no reference to it in issues, I assume that this should be available as the docs for ComprehendMedical are listed on the SDK browser:
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ComprehendMedical.html
In what npm package should comprehend medical be available?
I've tried importing the SDK by using both:
import { ComprehendMedical } from 'aws-sdk';
let comprehendmedical: ComprehendMedical = new ComprehendMedical();
and
import * as AWS from 'aws-sdk';
let comprehendmedical: AWS.ComprehendMedical = new AWS.ComprehendMedical();
NPM packages:
{
...
"typescript": "^3.1.6",
"aws-sdk": "^2.371.0"
...
}
Any info you can provide would be a massive help - thank you!
@abbottdev
ComprehendMedical was added to the SDK as of version v2.364.0, so that shouldn't be the issue.
Can you share details on how you're using webpack?
@srchase Thanks for getting back to me.
So, I'm trying to use create-react-app, which I then added typescript to. I understand CRA has an opinionated webpack implementation under the hood. (I'm sure I won't be the only person that tries this though... maybe one of the first? 馃槃 )
I've created a dummy project for you which reproduces the behaviour in the attached zip. (Note I didn't include node_modules so you'll need to npm install too, then npm start ).
If you want to get the full webpack definition, you can run npm run eject in the root of that folder and that will create the webpack.config.js if you wish to inspect the specifics of what it's doing under the hood.
What webpack requirements are there (If any)?
aws-comprehend-medical-ts-react.zip
Thanks 馃憤
@abbottdev
Could you publish the dummy project in a new repo?
@srchase
No worries - Published here: https://github.com/abbottdev/aws-comprehend-medical-ts
Is there anything more you need from me to help debug? 馃槂
Just a bit of further info - I may be completely off with this but if I try to consume this API using vanilla nodejs in an AWS lambda, I receive a similar response. So this may not be a typescript specific issue - but I figure this info may be helpful for you @srchase
Here's the lambda I'm attempting to use:
let AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
var cp = new AWS.ComprehendMedical({});
var params = {
Text: 'he has diabetes'
};
return cp.detectPHI(params, function(err, data) {
if (err) callback(err); // an error occurred
else {
console.log(data); // successful response
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify(data),
};
callback(response);
}
});
};
And the error stack I receive if I test this in the lambda console:
Function Logs:
START RequestId: a287c941-fbaa-11e8-bef7-4bea21fa5549 Version: $LATEST
2018-12-09T12:04:52.793Z a287c941-fbaa-11e8-bef7-4bea21fa5549 TypeError: AWS.ComprehendMedical is not a constructor
at exports.handler (/var/task/index.js:4:14)
END RequestId: a287c941-fbaa-11e8-bef7-4bea21fa5549
REPORT RequestId: a287c941-fbaa-11e8-bef7-4bea21fa5549 Duration: 50.57 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 26 MB
RequestId: a287c941-fbaa-11e8-bef7-4bea21fa5549 Process exited before completing request
Did you include your own version of the SDK with that Lambda function? Or use the Lambda-provided SDK?
The Lambda-provided version is currently at 2.290.0. See this Lambda documentation page for details.
We'll take a look at the TS repository.
I solve this problem doing this ->
importing from the path:
import AWS from 'aws-sdk/dist/aws-sdk-react-native';
@srchase - FYI - The above import @wedwin53 is using does allow us to consume the SDK, but I don't believe it's the intended way - As using the above import doesn't have any TS definition files, so we get no intellisense via the .d.ts files already in the sdk.
@abbottdev
We've made an internal request for the ComprehendMedical to support CORS which would enable this to be used from the browser (and included by the SDK in the default browser build).
Marking this as a feature-request.
A change for this has been merged. It will be available with the next release of the SDK.
Sweet, thanks @srchase
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.
Most helpful comment
A change for this has been merged. It will be available with the next release of the SDK.