Closed lgh89 closed 3 years ago
And I add follow code: let attachPolicyReq = AWSIoTAttachPolicyRequest() attachPolicyReq?.policyName = "TestFullPolicy" attachPolicyReq?.target = AWSMobileClient.default().getIdentityId().result! as String print(attachPolicyReq?.target as Any) AWSIoT.default().attachPolicy(attachPolicyReq!) { (error) in print("=======error", error as Any) }
but have error: error Optional(Error Domain=com.amazonaws.AWSIoTErrorDomain Code=19 "Not Found" UserInfo={NSLocalizedDescription=Not Found, NSLocalizedFailureReason=ResourceNotFoundException:})
Moving this to the SDK repo since this is for IoT.
Do you have TestFullPolicy
IAM policy defined in your AWS IoT Console? Looks like the error is ResourceNotFoundException
suggesting that the policy might not be present?
This issue is stale because it has been open for 14 days with no activity. Please, provide an update or it will be automatically closed in 7 days.
This issue is being automatically closed due to inactivity. If you believe it was closed by mistake, provide an update and re-open it.
Describe the bug
How can I attach the myIOTPolicy policy to the user’s Cognito Identity Id in code? Just like Android code: 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("")); // name of your IoT Region such as "us-east-1"
mIotAndroidClient.attachPolicy(attachPolicyReq);
I found that IOS does not have this part in the document, but Android does: https://docs.amplify.aws/sdk/pubsub/getting-started/q/platform/android#aws-iot