Reputation: 1
I have tried to call list users API using javascript sdk for AWS but got an error upon calling the API.
Code:
// Initialize the Amazon Cognito credentials provider
AWS.config.region = 'ap-northeast-2'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'my identity pool id',
});
AWS.config.accessKeyId = 'my access key id';
AWS.config.secretAccessKey = 'my secret access key';
var cognitoidentityserviceprovider = new
AWS.CognitoIdentityServiceProvider();
var myListUsers = function() {
var myparams = {
UserPoolId: 'my user pool id', /* required */
};
cognitoidentityserviceprovider.listUsers(myparams, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
Response:
TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.
at d (aws-sdk-2.144.0.min.js:47)
at o (aws-sdk-2.144.0.min.js:47)
at new i (aws-sdk-2.144.0.min.js:47)
at Object.update (aws-sdk-2.144.0.min.js:47)
at Object.hmac (aws-sdk-2.144.0.min.js:46)
at Object.getSigningKey (aws-sdk-2.144.0.min.js:46)
at constructor.signature (aws-sdk-2.144.0.min.js:46)
at constructor.authorization (aws-sdk-2.144.0.min.js:46)
at constructor.addAuthorization (aws-sdk-2.144.0.min.js:46)
at aws-sdk-2.144.0.min.js:43 "TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.
at d (https://sdk.amazonaws.com/js/aws-sdk-2.144.0.min.js:47:6802)
at o (https://sdk.amazonaws.com/js/aws-sdk-2.144.0.min.js:47:5442)
at new i (https://sdk.amazonaws.com/js/aws-sdk-2.144.0.min.js:47:5222)
at Object.update (https://sdk.amazonaws.com/js/aws-sdk-2.144.0.min.js:47:25616)
at Object.hmac (https://sdk.amazonaws.com/js/aws-sdk-2.144.0.min.js:46:24139)
at Object.getSigningKey (https://sdk.amazonaws.com/js/aws-sdk-2.144.0.min.js:46:16036)
at constructor.signature (https://sdk.amazonaws.com/js/aws-sdk-2.144.0.min.js:46:13643)
at constructor.authorization (https://sdk.amazonaws.com/js/aws-sdk-2.144.0.min.js:46:13581)
at constructor.addAuthorization (https://sdk.amazonaws.com/js/aws-sdk-2.144.0.min.js:46:12314)
at https://sdk.amazonaws.com/js/aws-sdk-2.144.0.min.js:43:13208"
This is an example from http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#listUsers-property
The code that I have used is the same one from the example. Can anyone give an advice to correct the error?
Thank you in advance.
Upvotes: 0
Views: 1217
Reputation: 11006
Try removing this bit:
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'my identity pool id',
});
I tested the code you posted (using Node 9.1.0 and aws-sdk
2.149.0) and got a different, but very similar looking error:
{ TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be one of type string, TypedArray, or DataView
at new Hmac (internal/crypto/hash.js:84:11)
at Object.createHmac (crypto.js:122:10)
at Object.hmac (D:\codecommit\cognitotest\node_modules\aws-sdk\lib\util.js:401:30)
at Object.getSigningKey (D:\codecommit\cognitotest\node_modules\aws-sdk\lib\signers\v4_credentials.js:59:8)
I removed the three lines above and things worked just fine.
Upvotes: 1