1

Here is the error I get:

AWSiOSSDKv2 [Error] AWSMobileAnalyticsDefaultDeliveryClient.m line:282 
| -[AWSMobileAnalyticsDefaultDeliveryClient submitEvents:andUpdatePolicies:] 
| Unable to successfully deliver events to server. Response code: 0. 
Error Message:
Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=6 
The operation couldn’t be completed.

I have AuthRole in IAM with the following policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "mobileanalytics:PutEvents",
        "cognito-sync:*"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}

And one Unauth role:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "mobileanalytics:PutEvents",
        "cognito-sync:*"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}

The string mention in IAM under cognito-identity.amazonaws.com:aud the conditions matches what is declared in my app.

I don't get where the problem is.

EDIT

The setup code (Swift).

private func _configureAWSServiceManager() {
    let credentialsProvider = AWSCognitoCredentialsProvider(
        regionType: Config().amazonRegionType,
        identityPoolId: Config().amazonCognitoIdentityPool)
    let configuration =
    AWSServiceConfiguration(region: Config().amazonRegionType,
        credentialsProvider: credentialsProvider)
    AWSServiceManager.defaultServiceManager().defaultServiceConfiguration =
    configuration
}

private func _configureMobileAnalytics() {
    let mobileAnalyticsConfiguration = AWSMobileAnalyticsConfiguration()
    mobileAnalyticsConfiguration.transmitOnWAN = true;

    let analytics = AWSMobileAnalytics(
        forAppId: Config().amazonMobileAnalyticsAppId,
        configuration: mobileAnalyticsConfiguration,
        completionBlock: nil)
    _analytics = analytics
}

Both are called successively in the AppDelegate in the application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) function.

EDIT / Solution: after another check it happens that a step of the creation of Cognito Identity Pool did create a role but this role was not assigned in unauthenticated role... Stupid thing, as always with the right management on AWS.

AsTeR
  • 7,247
  • 14
  • 60
  • 99

2 Answers2

3

The problem is related to CognitoIdentity, not MobileAnalytics. According to the doc, AWSCognitoIdentityErrorDomain Code=6 means InvalidIdentityPoolConfiguration.

"identity pool has no role associated for the given auth type (auth/unauth) or if the AssumeRole fails."

My Suggestion would be login to AWS Web Console -> Cognito, double check the settings of your Identity Pool. and Make sure the RegionType matched the one you created in the web console (upper right of the screen): CognitoIdentity current support us-east-1 and eu-west-1.

For MobileAnalytics, make sure you set configuration.serviceConfiguration.regionType to us-east-1 only.

http://docs.aws.amazon.com/AWSiOSSDK/latest/Constants/AWSCognitoIdentityErrorType.html

Yi Zhu
  • 166
  • 8
  • I didn't know that dichotomy between the supported zone in MobileAnalytics and Cognito. – AsTeR May 12 '15 at 20:06
  • Have you double check the configurations of the identity pool from AWS Web Console? Its seems that you are making unauthenticated call but there is no role associated to it. Go to AWS Portal-> Cognito -> Select your Identity pool -> Edit Identity Pool ( upper right corner) -> Unauthenticated role contains a valid role. If not, click "Create new role" to create a new one. – Yi Zhu May 12 '15 at 23:27
  • Just to conclude on that: yes, it was some stupid configuration issue. – AsTeR May 28 '15 at 16:12
2

It looks like you are trying to use a region other than AWSRegionUSEast1. The Amazon Mobile Analytics Service is currently only available in AWSRegionUSEast1.

Specifically:

AWSServiceConfiguration(region: Config().amazonRegionType,
    credentialsProvider: credentialsProvider)

Should be:

AWSServiceConfiguration(region: AWSRegionUSEast1,
    credentialsProvider: credentialsProvider)

While you can use any available Cognito Identity Region, events must be submitted to AWSRegionUSEast1.

let credentialsProvider = AWSCognitoCredentialsProvider(
        regionType: AWSRegionEUWest1,
        identityPoolId: Config().amazonCognitoIdentityPool)
let configuration = AWSServiceConfiguration(region: AWSRegionUSEast1,
        credentialsProvider: credentialsProvider)
Cheruvian
  • 5,628
  • 1
  • 24
  • 34