Aws-sdk-android: attachPrincipalPolicy deprecated

Created on 5 Dec 2018  路  3Comments  路  Source: aws-amplify/aws-sdk-android

attachPrincipalPolicy method is deprecated, documentation says that we should use attachPolicy, however AttachPolicyRequest does not have setPrincipal method to associate arn certificate.

Do you have an alternative code example?

com.amazonaws:aws-android-sdk-iot:2.8.4

IoT Needs Info from Requester Usage Question closing-soon-if-no-response

Most helpful comment

@logo17 you can use attachPolicy to set principal policy as follows :

import com.amazonaws.services.iot.AWSIotClient;
import com.amazonaws.services.iot.model.AttachPolicyRequest;

AttachPolicyRequest attachPolicyReq = new AttachPolicyRequest();
attachPolicyReq.setPolicyName("myIOTPolicy"); // name of your IoT AWS policy
attachPolicyReq.setTarget(AWSMobileClient.getInstance().getIdentityId());
AWSIotClient mIotAndroidClient = new AWSIotClient(AWSMobileClient.getInstance());
mIotAndroidClient.setRegion(Region.getRegion("MyRegion")); // name of your aws region such as "us-east-1"
mIotAndroidClient.attachPolicy(attachPolicyReq);

All 3 comments

@logo17 you can use attachPolicy to set principal policy as follows :

import com.amazonaws.services.iot.AWSIotClient;
import com.amazonaws.services.iot.model.AttachPolicyRequest;

AttachPolicyRequest attachPolicyReq = new AttachPolicyRequest();
attachPolicyReq.setPolicyName("myIOTPolicy"); // name of your IoT AWS policy
attachPolicyReq.setTarget(AWSMobileClient.getInstance().getIdentityId());
AWSIotClient mIotAndroidClient = new AWSIotClient(AWSMobileClient.getInstance());
mIotAndroidClient.setRegion(Region.getRegion("MyRegion")); // name of your aws region such as "us-east-1"
mIotAndroidClient.attachPolicy(attachPolicyReq);

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

thanks, it works..

Was this page helpful?
0 / 5 - 0 ratings