Reputation: 43
Working within Postman I'm trying to call a jwtToken from Cognito using node's aws-sdk but I'm getting the following error:
There was an error in evaluating the Pre-request Script: Error: Cannot find module 'aws-sdk'
This is my scrypt:
const AWS = require('aws-sdk');
var authenticationData = {
Username: 'username',
Password: 'password',
};
var authenticationDetails = new
AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
var poolData = {
UserPoolId: 'us-east-1_xxxxxx',
ClientId: 'xxxxx'
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var userData = {
Username: 'username',
Pool: userPool
};
var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function(result) {
var accessToken = result.getAccessToken().getJwtToken();
var idToken = result.idToken.jwtToken;
},
});
pm.globals.set("token", idToken);
So far the only commands I ran where: brew install node and npm install aws-sdk
I'm sure I'm missing some sort of configuration to call the module, Any help will do! Thnx!
Upvotes: 2
Views: 1428
Reputation: 403
Seems like Postman Sandbox cannot obtain a script's external dependencies.
You can leverage eval()
Javascript function to import additional Javascript code by having the code stored within a postman global or environment variable.
Example: eval(postman.getGlobalVariable('aws-sdk-code'))
See TIP #5: http://blog.getpostman.com/2017/07/28/api-testing-tips-from-a-postman-professional/
Also, you might encounter a later issue once the code executes as it seems you are requesting for AmazonCognitoIdentity
class in the amazon-cognito-identity-js
package.
https://www.npmjs.com/package/amazon-cognito-identity-js
Upvotes: 1