2

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?

Shibin Francis
  • 482
  • 6
  • 18

2 Answers2

2

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

Aarth Tandel
  • 1,001
  • 12
  • 32
  • If you give me the exact issue. It would be easy to answer :) – Aarth Tandel Sep 01 '17 at 06:40
  • We have our own signin authetication. Now, we want to integrate awt iot thing to our app. Putting certificates inside app for authetication is bad for secuirty purpose alone. All i see, is to go with cognito user pool. That means, i have to re-register users from backend to user pool. Is there a better way of doing authetication and use iot thing - @Aarth Tandel – kartic chaudhary Apr 10 '22 at 08:55
1

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.

pbx
  • 11
  • 1
  • AndroidPubSubWebSocket is the application name. I don't think that sample code supports IAM credential. It looks like we can use Cognito and Auth application session ID. I am facing another issue even when I am trying to connect through Cognito and Facebook combination. Authentication is successful and received facebook token. After that when I try connecting to AWS, it always shows "Reconnecting" status. I have no idea what is wrong in my side. [link]https://github.com/awslabs/aws-sdk-android-samples/issues/92[link] – Shibin Francis May 26 '17 at 08:59