Getting started

You are currently viewing the AWS SDK for Mobile documentation which is a collection of low-level libraries. Use the Amplify libraries for all new app development. Learn more

You can view the Mobile SDK API reference here.

PubSub provides connectivity with cloud-based message-oriented middleware. You can use PubSub to pass messages between your app instances and your app's backend creating real-time interactive experiences.

PubSub is available with AWS IoT.

Starting with version 12.1.1, iOS requires that publicly-trusted Transport Layer Security (TLS) server authentication certificates issued after October 15, 2018 meet the Certificate Transparency policy to be evaluated as trusted on Apple platforms. Any existing customer endpoint you have is most likely a VeriSign endpoint. If your endpoint has -ats at the end of the first subdomain, then it is an Amazon Trust Services endpoint. You can get an updated endpoint from the AWS console (AWS Console->IoT Core ->Settings page). For more details read: https://aws.amazon.com/blogs/iot/aws-iot-core-ats-endpoints/

Installation and Configuration

AWS IoT

When used with AWSIoTDataManager, PubSub is capable of signing request according to Signature Version 4.

The Podfile that you configure to install the AWS Mobile SDK must contain the AWSIoT pod:

1platform :ios, '9.0'
2
3target :'YOUR-APP-NAME' do
4 use_frameworks!
5
6 pod 'AWSIoT'
7 # other pods
8
9end

Run pod install --repo-update before you continue.

To use in your app, import the following:

1import AWSIoT

Define your unique client ID and endpoint (incl. region) in your configuration:

1// Initialize the AWSIoTDataManager with the configuration
2let iotEndPoint = AWSEndpoint(
3 urlString: "wss://xxxxxxxxxxxxx-ats.iot.<YOUR-AWS-REGION>.amazonaws.com/mqtt")
4let iotDataConfiguration = AWSServiceConfiguration(
5 region: AWSRegionType.<YOUR-AWS-REGION>,
6 endpoint: iotEndPoint,
7 credentialsProvider: AWSMobileClient.default()
8)
9
10AWSIoTDataManager.register(with: iotDataConfiguration!, forKey: "MyAWSIoTDataManager")
11let iotDataManager = AWSIoTDataManager(forKey: "MyAWSIoTDataManager")

You can get the endpoint information from the IoT Core -> Settings page on the AWS Console.

Create IAM policies for AWS IoT

To use PubSub with AWS IoT, you will need to create the necessary IAM policies in the AWS IoT Console, and attach them to your Amazon Cognito Identity.

Go to IoT Core and choose Secure from the left navigation pane, and then Policies from the dropdown menu. Next, click Create. The following myIOTPolicy policy will allow full access to all the topics.

Alt text

Attach your policy to your Amazon Cognito Identity

To attach the policy to your Cognito Identity, begin by retrieving the Cognito Identity Id from AWSMobileClient.

1AWSMobileClient.default().getIdentityId();

Then, you need to attach the myIOTPolicy policy to the user's Cognito Identity Id with the following AWS CLI command:

1aws iot attach-principal-policy --policy-name 'myIOTPolicy' --principal '<YOUR_COGNITO_IDENTITY_ID>'

Follow the instructions here if you are looking to:

  • Use AWS IoT for your Swift project using v2 of the Amplify Library for Swift
  • Migrate to v2 of the Amplify Library for Swift and you currently have an AWS IoT implementation in your project.