TLDR: I want grant Full IOT permissions to all users of a specified identity pool without having to manually attach the specified IOT policy to their Cognito ID as directed in the PubSub library post: aws iot attach-policy --policy-name 'myIoTPolicy' --target '<YOUR_COGNITO_IDENTITY_ID>'
https://docs.amplify.aws/lib/pubsub/getting-started/q/platform/js/
I am building a demo application in which I want to grant Unauthorized users IOT access priviledges (publish / subscribe to topic / etc.) I have a groupless Cognito userpool which connects to an identity pool that has a role for unauthorized users of the app. I have taken the following steps to (successfully) grant a specific unauthorized Cognito user IOT privileges.
Attach AWSIoTDataAccess and AWSIoTConfigAccess roles directly to Unauthorized identity pool role.
Attach my own IOT policy to the specific Cognito ID with the command aws iot attach-policy --policy-name 'myIoTPolicy' --target '<YOUR_COGNITO_IDENTITY_ID>'
This solution works, 100% of the time for the specified user. BUT, when a new user visits my app they will not have IOT access because "myIotPolicy" hasn't been explicitly attached to their Cognito ID. What's the workaround? In the future I will implement cognito User pool groups to specify guest / admin rights but I don't think that will help me here. Is there a way to programmatically attach the existing IOT policy to the cognito ID when the user visits the app for the first time? Any solution would be greatly appreciated!!!
Also - I am deploying these resources via serverless cloudformation (attached photo). I am using AWS:IoT::PolicyPrincipalAttachment to manually attach to the Cognito user id (Principal). Wondering if I can use some kind of !Ref to Cognito User ID.