- Newest
- Most votes
- Most comments
Hey Tom — great breakdown of the issue, and you're definitely close. The AUTHORIZATION_FAILURE despite a seemingly correct policy is a common but tricky AWS IoT Core + Cognito Identity problem.
🔍 Root Cause Hypothesis You're dynamically setting the MQTT clientId to the Cognito Identity ID, and your policy allows:
"Resource": "arn:aws:iot:us-east-2:<account-id>:client/${cognito-identity.amazonaws.com:sub}" But here’s the key detail:
🛑 sub and the Cognito Identity ID are not the same thing.
✅ Fix: Use ${cognito-identity.amazonaws.com:identity-id} Instead of sub In IAM, the policy should use:
"Resource": "arn:aws:iot:us-east-2:<account-id>:client/${cognito-identity.amazonaws.com:identity-id}" Because the MQTT clientId is typically set to the Cognito Identity ID, not the sub from the JWT.
So your current policy is allowing only clients named after the sub, which does not match your actual clientId, hence the AUTHORIZATION_FAILURE on iot:Connect.
✅ Corrected Policy Snippet { "Effect": "Allow", "Action": "iot:Connect", "Resource": "arn:aws:iot:us-east-2:<account-id>:client/${cognito-identity.amazonaws.com:identity-id}" } And if you're using that ID in topic names too, update those as well:
"Resource": [ "arn:aws:iot:us-east-2:<account-id>:topic/your-app/${cognito-identity.amazonaws.com:identity-id}/status", "arn:aws:iot:us-east-2:<account-id>:topic/your-app/${cognito-identity.amazonaws.com:identity-id}/notifications" ], "Resource": [ "arn:aws:iot:us-east-2:<account-id>:topicfilter/your-app/${cognito-identity.amazonaws.com:identity-id}/notifications" ] 🔁 Optional: Log the Identity ID To confirm it matches: const credentials = await Auth.currentCredentials(); console.log("Identity ID:", credentials.identityId); Best regards, Muhammad Zubair https://zeonedge.com
Relevant content
- asked 3 years ago
- asked 2 years ago
- asked 3 years ago
