Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

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:

platform :ios, '9.0'
target :'YOUR-APP-NAME' do
use_frameworks!
pod 'AWSIoT'
# other pods
end

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

To use in your app, import the following:

import AWSIoT

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

// Initialize the AWSIoTDataManager with the configuration
let iotEndPoint = AWSEndpoint(
urlString: "wss://xxxxxxxxxxxxx-ats.iot.<YOUR-AWS-REGION>.amazonaws.com/mqtt")
let iotDataConfiguration = AWSServiceConfiguration(
region: AWSRegionType.<YOUR-AWS-REGION>,
endpoint: iotEndPoint,
credentialsProvider: AWSMobileClient.default()
)
AWSIoTDataManager.register(with: iotDataConfiguration!, forKey: "MyAWSIoTDataManager")
let 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.

AWSMobileClient.default().getIdentityId();

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

aws 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.