Encountering a puzzling issue with a custom-built AWS-SDK. Perhaps it's just a case of me missing the forest for the trees, but it's driving me crazy. Here's what's happening.
I constructed an SDK incorporating all Cognito and DynamoDB services based on core version 2.247.1 as instructed by Amazon here.
When trying to require it in my code using the following snippet:
const AWS = require('../../../../assets/scripts/aws-sdk-2.247.1.js');
Furthermore, I followed the example implementation provided by AWS here.
Thus, I crafted the following code to retrieve a session for a logged-in user:
getUserSession(
response: ICognitoResponse,
callback: ( callbackResponse: ICognitoResponse ) => {} ) {
// Validate the Usersession
this.cognitoUser.getSession((err: any, session: any) => {
if (err) {
response = assign(response, { err });
callback( response );
return;
} else {
/**
* Set the right URL
* @type {string}
*/
const URL = 'cognito-idp.' +
environment.AWS_REGION +
'.amazonaws.com/' +
environment.USERPOOL_ID;
/**
* Update the Credentials with the current updated URL
* @type {AWS.CognitoIdentityCredentials}
*/
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
/**
* your identity pool id here
*/
IdentityPoolId: environment.USERPOOL_ID,
Logins: {
/**
* Change the key below according to the
* specific region your user pool is in.
*/
URL: session.getIdToken().getJwtToken(),
},
});
}
});
}
The compilation proceeds without errors, and I can log in successfully. However, immediately after that, I encounter the error:
Uncaught: TypeError: AWS.CognitoIdentityCredentials is not a constructor
If I use the same code with the full JavaScript SDK, which is quite massive, everything works as expected.
Hoping someone can provide some assistance. I've tried various import techniques like import * as AWS, but none have yielded successful results.