AttachPrincipalPolicyRequest policyAttachRequest = new AttachPrincipalPolicyRequest();
policyAttachRequest.setPolicyName(AWS_IOT_POLICY_NAME);
policyAttachRequest.setPrincipal(createKeysAndCertificateResult.getCertificateArn());
mIotAndroidClient.attachPrincipalPolicy(policyAttachRequest);
在这里,我想在AWS Iot中附加带有AWS证书的策略。 对于此操作,我正在使用attachPrincipalPolicy()函数。 但是此功能在'com.amazonaws:aws-android-sdk-iot:2.6.29'sdk版本中已弃用。 因此,每次创建证书后,我都需要手动将策略附加到证书。 使用aws证书附加策略还有其他方法吗?
答案 0 :(得分:0)
Ref:https://docs.aws.amazon.com/iot/latest/apireference/API_AttachPrincipalPolicy.html
AttachPrincipalPolicy
将指定的策略附加到指定的主体(证书) 或其他凭据)。
注意:不建议使用此API。请改为使用AttachPolicy。
编辑2
AttachPrincipalPolicyRequest attachPolicyReq = new AttachPrincipalPolicyRequest(); //in docs it called AttachPolicyRequest but it`s wrong
attachPolicyReq.setPolicyName("allAllowed"); //name of your IOTAWS policy
attachPolicyReq.setPrincipal(getIdRes.getIdentityId());
new AWSIotClient(credentialsProvider).attachPrincipalPolicy(attachPolicyReq);
https://github.com/awslabs/aws-sdk-android-samples/issues/92
答案 1 :(得分:0)
AWSIot awsIotClient = AWSIotClientBuilder.defaultClient();
awsIotClient.createPolicy(new CreatePolicyRequest().withPolicyDocument(policy).withPolicyName(policyName));
awsIotClient.attachPolicy(new AttachPolicyRequest().withPolicyName(policyName).withTarget("arn:aws:iot:<region>:<client_ID>:cert/<certificate_ID"