Michael Clifford
02/17/2022, 8:24 PMCognito construct. Can the same be achieved with the sst.Auth construct? I was wondering why my User Pool wasn't showing up in the console when I realized this.Frank
// Create User Pool
const userPool = new cognito.UserPool(this, "UserPool", {
selfSignUpEnabled: true,
signInAliases: { email: true },
signInCaseSensitive: false,
});
// Create User Pool Client
const userPoolClient = new cognito.UserPoolClient(this, "UserPoolClient", {
userPool,
authFlows: { userPassword: true },
});
Do this
const auth = new sst.Auth(this, "Auth", {
cognito: {
userPool: {
selfSignUpEnabled: true,
signInAliases: { email: true },
signInCaseSensitive: false,
},
userPoolClient: {
authFlows: { userPassword: true },
}
}
});
// auth.cognitoUserPool
// auth.cognitoUserPoolClientFrank
Michael Clifford
02/23/2022, 1:59 AMError: 'cliffom-sst-bff-demo-user-tasks-stack' depends on 'cliffom-sst-bff-demo-auth-stack' (cliffom-sst-bff-demo-user-tasks-stack -> cliffom-sst-bff-demo-auth-stack/Auth/UserPool/Resource.Arn). Adding this dependency (cliffom-sst-bff-demo-auth-stack -> cliffom-sst-bff-demo-user-tasks-stack/postConfirmationHandler/Resource.Arn) would create a cyclic reference.
The new code looks like this:
// Create User Pool and User Pool Client
const auth = new sst.Auth(this, 'Auth', {
cognito: {
userPool: {
selfSignUpEnabled: true,
signInAliases: {email: true},
signInCaseSensitive: false,
},
userPoolClient: {
authFlows: {userPassword: true},
idTokenValidity: Duration.days(1),
},
triggers: {
postConfirmation: props?.postConfirmationFunction,
},
},
});Michael Clifford
02/23/2022, 2:01 AMMichael Clifford
02/23/2022, 2:01 AM// Create User Pool
const userPool = new cognito.UserPool(this, 'UserPool', {
selfSignUpEnabled: true,
signInAliases: {email: true},
signInCaseSensitive: false,
lambdaTriggers: {
postConfirmation: props?.postConfirmationFunction,
},
});
// Create User Pool Client
const userPoolClient = new cognito.UserPoolClient(this, 'UserPoolClient', {
userPool,
authFlows: {userPassword: true},
idTokenValidity: Duration.days(1),
});Michael Clifford
02/23/2022, 2:02 AM// Create our single DynamoDB table
const tableStack = new TableStack(app, 'table-stack');
// Create our user tasks stack
const userTasksStack = new UserTasksStack(app, 'user-tasks-stack', {
table: tableStack.table,
});
// Create our Auth stack that defines our Cognito pool and client
const authStack = new AuthStack(app, 'auth-stack', {
postConfirmationFunction: userTasksStack.createUserFunction,
});Frank
auth.attachPermissionsForAuthUsers call anywhere?Michael Clifford
02/23/2022, 5:20 PMFrank
const userPool = new cognito.UserPool(this, 'UserPool', {
...
lambdaTriggers: {
postConfirmation: props?.postConfirmationFunction,
},
});
But this DOES NOT WORK, you will get the same cyclical dependency error.
const userPool = new cognito.UserPool(this, 'UserPool', {
...
});
userPool.addTrigger(cognito.UserPoolOperation.POST_CONFIRMATION, props?.postConfirmationFunction);Frank
AWS::Lambda::Permission resource is created in the UserTasks stack saying that ONLY this cognito pool can trigger this Lambda function (for security purposes). This causes the cyclical dependency error b/c
• UserTasksStack needs to know `AuthStack`’s UserPool ARN; and
• AuthStack needs to know `UserTasksStack`’s function ARNFrank
AWS::Lambda::Permission with undefined ARN, and any cognito user pool can trigger this function.Frank
UserTasksStack doesn’t depend on AuthStackFrank
sst.Auth always calls the addTrigger function, causing the cyclical dependency error.Frank
Frank
Auth?Michael Clifford
02/23/2022, 10:20 PMFrank
Frank
AWS::Lambda::Permission resource referencing the User Pool, and the AWS::Cognito::UserPool needs to reference the function’s ARN.Frank
Frank
AWS::Cognito::LambdaTrigger to break this cyclical dependency.Michael Clifford
02/23/2022, 11:21 PMMichael Clifford
02/23/2022, 11:35 PM