amplify-flutter icon indicating copy to clipboard operation
amplify-flutter copied to clipboard

PlatformException(AmplifyException, Failed to Configure Amplify, The operation couldn’t be completed.

Open bytewind-io opened this issue 6 years ago • 9 comments

PlatformException(AmplifyException, Failed to Configure Amplify, The operation couldn’t be completed. (Amplify.PluginError error 2.), null) [VERBOSE-2:profiler_metrics_ios.mm(184)] Error retrieving thread information: (ipc/send) invalid destination port Fatal error: Analytics category is not configured. Call Amplify.configure() before using any methods on the category.: file /Users/av/StudioProjects/dietian/flutter-customer-application/flutter-customer-application/ios/Pods/Amplify/Amplify/Categories/Analytics/AnalyticsCategory.swift, line 18 Lost connection to device.

[✓] Flutter (Channel beta, 1.22.0-12.2.pre, on Mac OS X 10.15.3 19D76, locale ru-UA)

Future initAwsAmplify(String amplifyconfig) async { final AmplifyAuthCognito auth = AmplifyAuthCognito(); //AmplifyStorageS3 storage = AmplifyStorageS3(); final AmplifyAnalyticsPinpoint analytics = AmplifyAnalyticsPinpoint();

await amplify.addPlugin(authPlugins: [auth],
    //storagePlugins: [storage],
    analyticsPlugins: [analytics]);
// Initialize AmplifyFlutter
await amplify.configure(amplifyconfig);
return true;

}

amplify_core: git: url: https://github.com/aws-amplify/amplify-flutter.git #ref: fix-auth-cognito-podfile #master ref: master path: packages/amplify_core/

amplify_auth_cognito: git: url: https://github.com/aws-amplify/amplify-flutter.git #ref: fix-auth-cognito-podfile #master ref: master path: packages/amplify_auth_cognito

amplify_analytics_pinpoint: git: url: https://github.com/aws-amplify/amplify-flutter.git #ref: fix-auth-cognito-podfile #master ref: master path: packages/amplify_analytics_pinpoint

Cognito working fine.

bytewind-io avatar Oct 13 '20 04:10 bytewind-io

Снимок экрана 2020-10-13 в 07 46 16

There is no error in android

bytewind-io avatar Oct 13 '20 04:10 bytewind-io

@cvalab Does your amplifyconfiguration.dart file have blocks for all three categories that you are adding (most importantly analytics, which is where the error is originating)?

haverchuck avatar Oct 13 '20 15:10 haverchuck

// ignore: leading_newlines_in_multiline_strings const amplifyconfig = ''' { "UserAgent": "aws-amplify-cli/2.0", "Version": "1.0", "api": { "plugins": { "awsAPIPlugin": { "api": { "endpointType": "GraphQL", "endpoint": "xxx", "region": "eu-west-2", "authorizationType": "AMAZON_COGNITO_USER_POOLS" } } } }, "auth": { "plugins": { "awsCognitoAuthPlugin": { "UserAgent": "aws-amplify-cli/0.1.0", "Version": "0.1.0", "IdentityManager": { "Default": {} }, "CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId": "xxx", "Region": "eu-west-2" } } }, "CognitoUserPool": { "Default": { "PoolId": "xxx", "AppClientId": "xxx", "AppClientSecret": "xxx", "Region": "eu-west-2" } }, "AppSync": { "Default": { "ApiUrl": "xxx", "Region": "eu-west-2", "AuthMode": "AMAZON_COGNITO_USER_POOLS", "ClientDatabasePrefix": "api_AMAZON_COGNITO_USER_POOLS" } } } } }, "analytics": { "plugins": { "awsPinpointAnalyticsPlugin": { "pinpointAnalytics": { "appId": "xxx", "region": "eu-west-2" } } } } }''';

bytewind-io avatar Oct 14 '20 13:10 bytewind-io

@cvalab The configuration does not seem to be generated by the CLI but rather hand written, is that correct? I'm not sure about why Android did not throw an error, but I think your config is missing some attributes such as pinpointTargeting

I've provided a sample configuration file for Auth, Storage and Analytics with using a default setup, which you can try and emulate and see if you don't get the error then.

const amplifyconfig = '''
{
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "analytics": {
        "plugins": {
            "awsPinpointAnalyticsPlugin": {
                "pinpointAnalytics": {
                    "appId": "xxx",
                    "region": "us-east-1"
                },
                "pinpointTargeting": {
                    "region": "us-east-1"
                }
            }
        }
    },
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "xxx",
                            "Region": "us-east-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "xxx",
                        "AppClientId": "xxx",
                        "AppClientSecret": "xxx",
                        "Region": "us-east-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH"
                    }
                },
                "PinpointAnalytics": {
                    "Default": {
                        "AppId": "xxx",
                        "Region": "us-east-1"
                    }
                },
                "PinpointTargeting": {
                    "Default": {
                        "Region": "us-east-1"
                    }
                },
                "S3TransferUtility": {
                    "Default": {
                        "Bucket": "xxx",
                        "Region": "us-east-1"
                    }
                }
            }
        }
    },
    "storage": {
        "plugins": {
            "awsS3StoragePlugin": {
                "bucket": "xxx",
                "region": "us-east-1",
                "defaultAccessLevel": "guest"
            }
        }
    }
}
''';

Ashish-Nanda avatar Oct 15 '20 12:10 Ashish-Nanda

hi all,

I work with @cvalab on the same project, I'm the backend developer. We are using a hand written config as our backend is deployed with CDK instead of amplify. Our goal is for the 2 items to work:

  1. integrate Cognito user pools with AWS pinpoint
  2. Generally get AWS pinpoint analytics working so that we can log analytics events.

After some thorough digging, I've found the following (some comments not for Amplify team but would be good to get noted).

  1. Our config now looks as follows:
 {
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "api": {
        "plugins": {
            "awsAPIPlugin": {
                "api": {
                    "endpointType": "GraphQL",
                    "endpoint": "{value}",
                    "region": "eu-west-2",
                    "authorizationType": "AMAZON_COGNITO_USER_POOLS"
                }
            }
        }
    },
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "{value}",
                            "Region": "eu-west-2"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "{value}",
                        "AppClientId": "{value}",
                        "AppClientSecret": "{value}",
                        "Region": "eu-west-2"
                    }
                },
                "AppSync": {
                    "Default": {
                        "ApiUrl": "{value}",
                        "Region": "eu-west-2",
                        "AuthMode": "AMAZON_COGNITO_USER_POOLS",
                        "ClientDatabasePrefix": "api_AMAZON_COGNITO_USER_POOLS"
                    }
				},
				"PinpointAnalytics": {
                    "Default": {
                        "AppId": "{value}",
                        "Region": "eu-west-2"
                    }
                },
                "PinpointTargeting": {
                    "Default": {
                        "Region": "eu-west-2"
                    }
                }
            }
        }
    },
	"analytics": {
        "plugins": {
			"awsPinpointAnalyticsPlugin": {
                "pinpointAnalytics": {
                    "appId": "{value}",
                    "region": "eu-west-2"
                },
                "pinpointTargeting": {
                    "region": "eu-west-2"
                }
            }
        }
    }
}
  1. I've mimicked the authRole and unAuthRole permissions that get assigned based on the cognito identity provider roles. Basically added the following in CDK, below is an excerpt of the type script policy statement attached to auth and unauth roles:
new iam.PolicyStatement({
								effect: iam.Effect.ALLOW,
								actions: [
									'mobiletargeting:PutEvents',
									'mobiletargeting:UpdateEndpoint',
									'mobiletargeting:GetUserEndpoints'
								],
								resources: [
									cdk.Fn.join('', [
										// pinpointProject.attrArn,
										'{pinpoint project arn}',
										'/*'
									])
								],
							}),

After this, we now have the analytics category successfully working. ( ** 2. Generally get AWS pinpoint analytics working so that we can log analytics events. ** listed above). From this, I'd suggest updating these docs: https://docs.amplify.aws/lib/analytics/existing-resources/q/platform/flutter to include information about idp role permissions that need to be assigned as well as to include:

"PinpointTargeting": {
                    "Default": {
                        "Region": "eu-west-2"
                    }
                }

After getting this config correct, we then tried to deploy our pinpoint project via cloudformation (in eu-west-2) only to find that the cloudformation service in eu-west-2 does not support pinpoint (I assume that's why amplify deploys via lambda function instead?). This also removed the IOS error we were experiencing:

PlatformException(AmplifyException, Failed to Configure Amplify, The operation couldn’t be completed. (Amplify.PluginError error 2.), null)
[VERBOSE-2:profiler_metrics_ios.mm(184)] Error retrieving thread information: (ipc/send) invalid destination port
Fatal error: Analytics category is not configured. Call Amplify.configure() before using any methods on the category.: file /Users/av/StudioProjects/dietian/flutter-customer-application/flutter-customer-application/ios/Pods/Amplify/Amplify/Categories/Analytics/AnalyticsCategory.swift, line 18
Lost connection to device.

I'm not sure if the idp role's was the fix or adding "PinpointTargeting", either way, it may indicate updating this error message to be more helpful.

Then, we want to integrate cognito with pinpoint but it's impossible to select our pinpoint project from our cognito userpool, even when our cloudformation template successfully deploys, it just blanks out the application Id:

Screenshot 2020-10-15 at 14 09 53

And in the above, I can only select pinpoint projects in us-east-1, even though this notice in the docs

Screenshot 2020-10-15 at 14 14 47

Implies that I should be able to select my pinpoint project as pinpoint is available in eu-west-2 (although not in cloudformation) and event if my pinpoint project is in eu-west-1, I can't select it. Unfortunately we need our data based in the EU for GDPR and other EU privacy reasons. So, should I be able to select this option (is this a bug or working as intended?)

And finally, we use a custom auth strategy for various reasons. Basically we create a user in appsync and DynamoDb and then call adminCreateUser in cognito. What implications does this have instead of using cognito signUp method as none of the admin cognito actions take an AnalyticsEndpointId parameter and I'm worried this may impact the cognito -> pinpoint integration. Again, it's unclear because this page https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-pinpoint-integration.html has very little information about what actually happens on this integration

remaining questions & points:

  1. what does "PinpointTargeting" in the auth category section do?
  2. what does "PinpointTargeting" in the analytics category section do?
  3. Does amplify flutter automatically request endpoint Id on app open and does it populate cognito requests with this ID automatically? (I assume this is the analyticsEndpointId param on cognito requests)
  4. Does this configuration (both front end and backend in terms of user roles) look correct for AWS pinpoint analytics (not for cognito integration [point 1 list above])
  5. Is the cognito -> pinpoint integration only available in us-east-1, even though pinpoint is available in eu-west-2?
  6. What does the cognito -> pinpoint integration actually do, in case we need to re-create this functionality as it's unclear in this doc which should potentially include some more info: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-pinpoint-integration.html )
  7. How is the cognito -> pinpoint integration affect by custom auth strategies such as using adminCreateUser behind the scenes to sign up a user?
  8. From my research, it seems like there's a real lack of pinpoint documentation on technical usage (for instance no mention anywhere about the cognito AnalyticsEndpointId parameter that I could see and not enough information about how pinpoint works with Cognito which may really be negatively impacting other developers looking to use Pinpoint as an alternative to other providers out there (especially those working on projects where Amplify CLI is not the right fit from a backend perspective)

Sorry for the long message, happy to post some of this feedback on other channels if this is not the right place for all of it and honestly we are really enjoying working with Amplify Flutter so far -> will be sure to provide more feedback as we go.

danielblignaut avatar Oct 15 '20 13:10 danielblignaut

@danielblignaut Thank you for the feedback and also for providing so much detail on your issue integrating Cognito and Pinpoint.

I'm glad that adding the pinpointTargeting attribute to your config and updating your permissions in the policy got you past the exception that was being thrown, and you have use-case 2 (Generally get AWS pinpoint analytics working so that we can log analytics events) working. Will make sure to update our docs with the additional attributes.

Regarding your custom setup and issues/questions on integrating the existing Cognito and Pinpoint backend resources in the EU region, I'll need to pull in someone from the CLI team since they work closely with deploying and integrating the different services.

They might know more about why you are not able to select the pinpoint project despite both services being available in the region. I did find find this comment which states sending events to Amazon Pinpoint projects is only supported in the US East (N. Virginia) us-east-1, but it contradicts the cognito docs you pointed out so I'll need some time to confirm.

I'll ensure we answer all the questions listed once we have more info.

Ashish-Nanda avatar Oct 15 '20 15:10 Ashish-Nanda

hey @Ashish-Nanda ,

are there any updates on this?

danielblignaut avatar Oct 21 '20 09:10 danielblignaut

Hi @danielblignaut sorry for the rather late reply here - do you need help on this issue anymore?

fjnoyp avatar Jun 29 '22 18:06 fjnoyp

Closing this issue due to inactivity.

haverchuck avatar Jul 15 '22 18:07 haverchuck