Closed amarpulli1994 closed 4 years ago
Please check this code https://github.com/aws-amplify/aws-sdk-android/issues/600#issuecomment-444793515
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);
@kirantpatil I tried its not working
@kirantpatil There is no attachpolicyrequest.
@rjuliano, Any updates on this issue ?
Why no one is answering to this question, we even went and purchased aws developer subscription to my surprise they are again asking us to go back to github.
What should we do, since we are struck here ?
Thank you.
Dear @anuragdce,
Did you face this issue ?
Thanks.
I think you need to add below code. Found at https://stackoverflow.com/questions/44244375/aws-iot-android-application-over-mqtt-throws-mqttexception-0-java-io-ioexcep
AmazonCognitoIdentity cognitoIdentity = new AmazonCognitoIdentityClient(credentialsProvider);
GetIdRequest getIdReq = new GetIdRequest();
getIdReq.setLogins(logins); //or if you have already set provider logins just use credentialsProvider.getLogins()
getIdReq.setIdentityPoolId(COGNITO_POOL_ID);
GetIdResult getIdRes = cognitoIdentity.getId(getIdReq);
Hi all, After spent lot of time..found mistake. In my case the attach policy request api by default it will take us-east-1. So here we have to set end point and as well as region also. Then only it will work. Here is the sample code.
AttachPrincipalPolicyRequest principalPolicyRequest = new AttachPrincipalPolicyRequest();
principalPolicyRequest.setPolicyName("iotPolicy");
principalPolicyRequest.setPrincipal(credentialsProvider.getIdentityId());
AWSIotClient awsIotClient = new AWSIotClient(credentialsProvider);
awsIotClient.setEndpoint(CUSTOMER_SPECIFIC_ENDPOINT);
awsIotClient.setRegion(Region.getRegion(Regions.AP_SOUTH_1));
awsIotClient.attachPrincipalPolicy(principalPolicyRequest);
Hi all, After spent lot of time..found mistake. In my case the attach policy request api by default it will take us-east-1. So here we have to set end point and as well as region also. Then only it will work. Here is the sample code.
AttachPrincipalPolicyRequest principalPolicyRequest = new AttachPrincipalPolicyRequest(); principalPolicyRequest.setPolicyName("iotPolicy"); principalPolicyRequest.setPrincipal(credentialsProvider.getIdentityId()); AWSIotClient awsIotClient = new AWSIotClient(credentialsProvider); awsIotClient.setEndpoint(CUSTOMER_SPECIFIC_ENDPOINT); awsIotClient.setRegion(Region.getRegion(Regions.AP_SOUTH_1)); awsIotClient.attachPrincipalPolicy(principalPolicyRequest);
I have been trying to fix my issue for days. You are awesome. Thank you!
Hi All,
I am trying to do attaching policy request for cognito identity user using programmatically instead using aws cli. Through aws cli attaching successfully and also working fine. But programmatically not working. It gives exception like Cognito Identity not configured . This is my sample code
I am getting below exception
Exception : com.amazonaws.AmazonClientException: Cognito Identity not configured
By using below command is working fine.
aws iot attach-principal-policy --policy-name <iot-policy-name> --principal <cognito-identity-id>
Please guide me how to attach policy request through programmatically.Thanks in Advance.