Philipp Schlösser
Philipp Schlösser

Reputation: 5219

Amazon Mobile Analytics without using Cognito

I would like to use Amazon Mobile Analytics for iOS without using a Cognito identity pool for the authentication. I am aware that this post stats that I can't but the Mobile Analytics FAQ state:

Q: Do I need to use Amazon Cognito to use the Amazon Mobile Analytics service?

No. You can initialize Amazon Mobile Analytics using AWS IAM accounts. However, we recommend using Amazon Cognito for security best practices. Detailed documentation for both methods can be found here.

However, there is absolutely no detailed documentation on how to use Mobile Analytics with an IAM user. I already set up an IAM user and gave it the appropriate permissions to write to Mobile Analytics. I just don't know how to use this user in the iOS AWS Mobile Framework.

Can anybody help me with that or are the cited FAQs just out of date?

Upvotes: 0

Views: 475

Answers (1)

Philipp Schlösser
Philipp Schlösser

Reputation: 5219

I found the solution in this post from the AWS developer forum.

Here is the complete code you need to initialize AWS Mobile Analytics for iOS using an IAM user instead of Cognito:

AWSStaticCredentialsProvider *credentialsProvider = 
    [[AWSStaticCredentialsProvider alloc]
  initWithAccessKey:@"IAM_USER_ID"
          secretKey:@"IAM_USER_SECRET"];

AWSServiceConfiguration *serviceConf = 
    [[AWSServiceConfiguration alloc]
       initWithRegion:AWSRegionUSEast1
  credentialsProvider:credentialsProvider];

AWSMobileAnalyticsConfiguration *analyticsConf = [AWSMobileAnalyticsConfiguration new];
analyticsConfig.serviceConfiguration = serviceConf;

AWSMobileAnalytics *analytics = [AWSMobileAnalytics
    mobileAnalyticsForAppId:@"MOBILE_ANALYTICS_APP_ID"
              configuration: analyticsConfig
            completionBlock:^(AWSMobileAnalytics *mobileAnalytics) {}];

Upvotes: 0

Related Questions