aws-amplify / aws-sdk-ios

AWS SDK for iOS. For more information, see our web site:
https://aws-amplify.github.io/docs
Other
1.68k stars 885 forks source link

How can I attach the myIOTPolicy policy to the user’s Cognito Identity Id in code? #3574

Closed lgh89 closed 3 years ago

lgh89 commented 3 years ago

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

lgh89 commented 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:})

palpatim commented 3 years ago

Moving this to the SDK repo since this is for IoT.

royjit commented 3 years ago

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?

github-actions[bot] commented 3 years ago

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.

github-actions[bot] commented 3 years ago

This issue is being automatically closed due to inactivity. If you believe it was closed by mistake, provide an update and re-open it.