undefined is not an object (evaluating 'cognitoClient.initWithOptions')
whoknowsjas opened this issue · 8 comments
Trying to test this out but running into an issue. At face value it appears that the NativeModules.AWSRNCognitoCredentials is not loading... but not sure if symptom or cause. Ideas?
Note I am running android simulation, and here is the abbrev. code:
...
import {AWSLambda} from 'aws-sdk-react-native-lambda';
import {AWSCognitoCredentials} from 'aws-sdk-react-native-core';
var functionName = "sampleFunction";
var cognitoRegion = "us-east-1";
var identity_pool_id = "us-east-1:xxxx";
var serviceRegion = "us-east-1";
...
async Setup() : Promise {
Promise.all([AWSCognitoCredentials.initWithOptions({"region":cognitoRegion,"identity_pool_id":identity_pool_id})]).then(()=>{
AWSLambda.initWithOptions({"region":serviceRegion});
});
return;
}
async _invokeRequest() {
await this.Setup();
var shouldResolve = false;
var req = {
"FunctionName" : function,
"InvocationType" : "RequestResponse",
"LogType" : "None",
"ClientContext" : this.encode(JSON.stringify({"System":"android"})),
"Payload" : JSON.stringify({"email":"testing1234"})
};
try{
console.log("testing...");
var response = AWSLambda.Invoke(req);
if(response.LogResult){
console.error("response.LogResult should not be present");
shouldResolve = false;
return shouldResolve;
}
if(!response.Payload){
console.error("response.Payload is not present");
shouldResolve = false;
return shouldResolve;
}
if(response.Payload.Length === 0){
console.error("response.Payload.Length is 0. Response payload length: " + response.Payload.Length);
shouldResolve = false;
return shouldResolve;
}
if(response.StatusCode === 0){
console.error("response.StatusCode is 0. Response code: " + response.StatusCode);
shouldResolve = false;
return shouldResolve;
}
} catch(e) {
console.error(e);
shouldResolve = false;
return shouldResolve;
}
}
...
I have the same problem. Android. Samsung S6.
Are there things missing from the README. Do we need to add external libraries (the Android AWS SDK) to make this work?
This fixed the issue (a bad installation more likely) for Android.
Add this line
compile 'com.amazonaws:aws-android-sdk-core:2.2.+'
in the dependencies of android/app/build.gradle if it's not there.
[How I got there:
I went to my node_modules/aws-sdk-react-native-core/android/build.gradle
saw this:
dependencies {
compile 'com.facebook.react:react-native:+'
compile 'com.amazonaws:aws-android-sdk-core:+'
}
From there, I got to this
http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/setup.html
used option 1 (my IDE is not Android Studio but I do use it) and voilà! :)]
Thanks for the tip, although it didn't work for me. I added the entry in the build.gradle and confirmed it downloaded the dependency in the build... but still get: "undefined is not an object (evaluating 'cognitoClient.initWithOptions')" when running.
I'm using Deco for IDE but I even tried running it in the terminal and still no good. Any other ideas?
I'd suggest may be looking into your own node_modules/aws-sdk-react-native-core/ (may be the lambda one too) and see if there are any other dependencies out there. Right now, I moved on trying the other services (meaning I am not using the lambda service yet. if you are, you'd probably have to add its dependencies too I guess)
Sorry no other ideas. Good luck!
(you may want to go with the jars too [Option 2 in the link]. Though I tried it earlier and it generated an error about how the class AmazonClientException was coming from different sources)
Back to my code, I realised I did a number of things when I first got the error. Here is what I recall doing manually. (I hope it helps but general advice is to track down the dependencies.)
___android/settings.gradle
include ':aws-sdk-react-native-core'
project(':aws-sdk-react-native-core').projectDir = new File(settingsDir, '../node_modules/aws-sdk-react-native-core/android')
___in my MainApplication.java
import com.amazonaws.reactnative.core.AWSRNCorePackage;
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
...
, new AWSRNCorePackage()
);
}
That last part worked! Importing and loading explicitly in the MainApp class works... like you said must be something wrong with the install. For now this will do. Thanks again for the help!
I'm having this same issue under iOS. I suspect it's something to do with the code in the node-modules folders not compiling against the SDK framework files I've included in the Xcode project for my app.
Can anyone suggest how to get past this roadblock?