Я использую настройку API AppSync с AWS Amplify, я получаю следующую ошибку. Методы авторизации как IAM, так и Cognito Pool не выполняются и выдают эту ошибку. Когда я использую ключ API, нет проблем.
2019-05-15 23:15:44.215 15058-15058/com.example.aaa.amplify E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.aaa.amplify, PID: 15058
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.aaa.amplify/com.example.aaa.amplify.MainActivity}: java.lang.RuntimeException: Failed to read awsconfiguration.json please check that it is correctly formed.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.RuntimeException: Failed to read awsconfiguration.json please check that it is correctly formed.
at com.amazonaws.mobile.config.AWSConfiguration.readInputJson(AWSConfiguration.java:99)
at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:83)
at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:68)
at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:45)
at com.example.aaa.amplify.MainActivity.onCreate(MainActivity.java:33)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: org.json.JSONException: End of input at character 1241 of { "UserAgent": "aws-amplify-cli/0.1.0", "Version": "1.0", "IdentityManager": { "Default": {} }, "AppSync": { "Default": { "ApiUrl": "https://xxxxxxxx.appsync-api.us-west-2.amazonaws.com/graphql", "Region": "us-west-2", "AuthMode": "API_KEY", "ApiKey": "da2-xxxxxxxxxxxxxxxx", "ClientDatabasePrefix": "xxxxxxxxxxxxxxx-master_API_KEY" },// "Default": {// "ApiUrl": "https://xxxxxxxxxxxx.appsync-api.us-west-2.amazonaws.com/graphql",// "Region": "us-west-2",// "AuthMode": "AWS_IAM",// "ClientDatabasePrefix": "xxxxxxxx-master_AWS_IAM"// }, }, "CognitoUserPool": { "Default": { "PoolId": "us-west-xxxxxxx", "AppClientId": "xxxxxxxxxxxxx", "AppClientSecret": "xxxxxxxxxxxxxxxxxx", "Region": "us-west-2" } }, "Auth": { "Default": { "OAuth": { "AppClientId": "xxxxxxxxxxxxxxxxxxxxxxx", "AppClientSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" } } }}
at org.json.JSONTokener.syntaxError(JSONTokener.java:449)
at org.json.JSONTokener.nextValue(JSONTokener.java:97)
at org.json.JSONTokener.readObject(JSONTokener.java:361)
at org.json.JSONTokener.nextValue(JSONTokener.java:100)
at org.json.JSONTokener.readObject(JSONTokener.java:384)
at org.json.JSONTokener.nextValue(JSONTokener.java:100)
at org.json.JSONObject.<init>(JSONObject.java:156)
at org.json.JSONObject.<init>(JSONObject.java:173)
at com.amazonaws.mobile.config.AWSConfiguration.readInputJson(AWSConfiguration.java:97)
at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:83)
at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:68)
at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:45)
at com.example.aaa.amplify.MainActivity.onCreate(MainActivity.java:33)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
1004 *
Я попытался напрямую подключить API к проекту и выполнить автоматическую настройку с усилением add codegen xxxxxxxxxxxx. Мне не повезло
мой файл awsconfiguration.json:
//WORKS
"AppSync": {
"Default": {
"ApiUrl": "https://xxxxxxxxxxxxxxx.appsync-api.us-west-2.amazonaws.com/graphql",
"Region": "us-west-2",
"AuthMode": "API_KEY",
"ApiKey": "da2-xxxxxxxx",
"ClientDatabasePrefix": "xxxxxx-master_API_KEY"
},
//DOES NOT WORK
// "Default": {
// "ApiUrl": "https://xxxxxxxxxxxxxx.appsync-api.us-west-2.amazonaws.com/graphql",
// "Region": "us-west-2",
// "AuthMode": "AWS_IAM",
// "ClientDatabasePrefix": "xxxxx-master_AWS_IAM"
// },
//DOES NOT WORK
// "Default": {
// "ApiUrl": "https://xxxxxxxxxxxxxx.appsync-api.us-west-2.amazonaws.com/graphql",
// "Region": "us-west-2",
// "AuthMode": "AMAZON_COGNITO_USER_POOLS",
// "ClientDatabasePrefix": "xxxxxxxxxxx-master_AMAZON_COGNITO_USER_POOLS"
// },
Когда я использую ключ API, я могу подключиться к серверной части, но когда я пытаюсь использовать роль user_pool или IAM для аутентификации, я получаю сообщение об ошибке. Для разработки API в порядке, но теперь правильной настройкой является использование одного из других методов, Cognito pool или IAM
.