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.
When used with
AWSIoTDataManager, PubSub is capable of signing request according to Signature Version 4.
Podfile that you configure to install the AWS Mobile SDK must contain the
1platform :ios, '9.0'23target :'YOUR-APP-NAME' do4 use_frameworks!56 pod 'AWSIoT'7 # other pods89end
pod install --repo-update before you continue.
To use in your app, import the following:
Define your unique client ID and endpoint (incl. region) in your configuration:
1// Initialize the AWSIoTDataManager with the configuration2let 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)910AWSIoTDataManager.register(with: iotDataConfiguration!, forKey: "MyAWSIoTDataManager")11let iotDataManager = AWSIoTDataManager(forKey: "MyAWSIoTDataManager")
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.
Attach your policy to your Amazon Cognito Identity
To attach the policy to your Cognito Identity, begin by retrieving the
Cognito Identity Id from
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>'