AWS IoT login from android MQTT client using IAM i

2019-05-23 03:40发布

问题:

I have been trying to connect my android application to AWS IoT portal. I have created an IAM account, which has a username and password. I have gone through the documentation but I could not see any proper guideline. I read somewhere that I can access the IoT devices through IAM/Cognito/using a certificate. Since I am an Android user I can't(I don't want to) use a device certificate. Can I use my IAM credentials to access my AWS IoT devices? I have downloaded all sample application and I could not find any working code. Or could someone explain how can I access AWS IoT portal from android app?

回答1:

Seeing your comments and questions. I had the similar issues when working with AndroidPubSubWebSocket. Make sure you are giving appropriate permission to publish and subscribe to the thing as given in the Github repo instruction by AWS. Assuming that has been done.

  1. The sample provided in the Github AndroidPubSuB is only for the unauthenticated user. For authenticated user (Here Facebook) few things have to be added both on AWS side and Android Side

Android

Map<String, String> logins = new HashMap<String, String>();
        logins.put("graph.facebook.com", AccessToken.getCurrentAccessToken().getToken());
        credentialsProvider.setLogins(logins);

The above code is necessary as it is used by AwsCredentialProvider for authentication of the user for publishing and connecting to the thing.

After you are done with above head here. Follow the answer by Caleb and do the exact steps.

After this, you are good to go.

  1. For Unauthenticated user create a pool for users and region in AWS. Get the thing end point. Make the appropriate changes.

To get the changes to the shadow type the following in the sample android(WebSocketAwsOubSub) edit box $aws/things/thing_name/shadow/update/accepted

And to publish the data to the shadow type $aws/things/thing_name/shadow/update



回答2:

The sample application has some constant that you would need to replace with your own values, such as the cognito pool Id, your IoT endpoint. In IAM you would also need to give proper IoT permissions so that you app may connect to IoT and do publish/subscribes. Which sample application are you having issue using ? And at which particular step do you have questions?

Thanks.