I'm trying to add some permission to the preSignUp lambda trigger of Auth (such as cognito:ListUsers) but cannot achieve it.
I have tried to create a custom function and use the cdk to grant the access and attach to auth trigger as:
// amplify/backend.ts
import { defineBackend } from '@aws-amplify/backend';
import { auth } from './auth/resource';
import { data } from './data/resource';
import { UserPool, UserPoolOperation } from 'aws-cdk-lib/aws-cognito';
import { preSignUpLambda } from './functions/preSignUp/resource';
const backend = defineBackend({
auth,
data,
preSignUpLambda
});
const userPool = backend.auth.resources.userPool as UserPool
userPool.addTrigger(UserPoolOperation.PRE_SIGN_UP, backend.preSignUpLambda.resources.lambda)
userPool.grant(backend.preSignUpLambda.resources.lambda, "cognito:ListUsers")
But the above solution produce the error:
The CloudFormation deployment has failed. Find more information in the CloudFormation AWS Console for this stack.
Caused By: ❌ Deployment failed: Error [ValidationError]: Circular dependency between resources: [auth179371D7, data7552DF31, function1351588B]
I can only add the trigger function by adding this in /amplify/auth/resource.ts
triggers: {
preSignUp: preSignUpLambda
}
But if I do this, I cannot find any object of the function in backend.auth.resource
So is there any workaround to do this or it's just impossible at the moment?
Thank you in advance 
