I'm working on a multi-tenant application on AWS. I am struggling to implement multi-tenant on cognito. My first approach was to use one Cognito User Pool and an Identity Pool for the whole application.
For the moment we have two kinds of user per tenant (administrators and regular users) so I want to assign them different IAM Roles.
The idea was to create a Cognito Group for each user role and to associate them with respective IAM Roles. It works ok. When using groups for roles assignment, I configured the identity pool authenticated role selection to 'Choose role from token'.
However, with 20 tenants, 40 groups will be needed, and the limits for Cognito Groups are 25 for each User Pool.
Using a Cognito User Pool per tenant has the same inconvenient since limits for Cognito User Pool is 50 (and we expect more than 25 tenants).
These are soft limits, so I know that it is possible to ask for increase it. In fact, I requested to increase Cognito Groups Limit but the answer is taking too long.
As an alternative to Cognito Group I could configure the identity pool authenticated role selection to 'Choose role with rules'.
In this way I added a Cognito User Pool custom attribute (custom:role) and configured Identity Pool Cognito Authenticate Provider with rules like the following:
if custom:role equals 'tenant1_admin' then assign TENANT_1_ADMIN_IAM_ROLE
if custom:role equals 'tenant1_regular' then assign TENANT_1_REGULAR_IAM_ROLE
...
if custom:role equals 'tenant20_admin' then assign TENANT_20_ADMIN_IAM_ROLE
if custom:role equals 'tenant20_regular' then assign TENANT_20_REGULAR_IAM_ROLE
Is this a correct way to implement multi-tenant on Cognito? As far as I know, there are no limits to Identity Pool Authenticate Providers rules number.