aws-cdk: [cognito] can't add cognito trigger after UserPool.fromUserPoolId
version:
"@aws-cdk/aws-cognito": "^1.60.0",
Code
const amplifyUserPool = cognito.UserPool.fromUserPoolId(
this,
"amplifyUserPool",
"us-east-1_ABCDE"
);
console.log("addTrigger" in amplifyUserPool);
Expect
true
Receive
false
Documentation
Importing User Pools addTrigger
More
The documentation indeed mentions:
However, imported user pools have limited configurability. As a rule of thumb, none of the properties that is are part of the AWS::Cognito::UserPool CloudFormation resource can be configured.
But when I was using serverless framework, it works like a charm.
Just wonder any workarounds against this? I want to move my full serverless stack to CDK, it is such a beautiful tech.
- There is a stackoverflow question against this: https://stackoverflow.com/questions/61816264/add-lambda-trigger-to-imported-cognito-user-pool-with-aws-cdk
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 18
- Comments: 23 (5 by maintainers)
I was not able to get the above solution working as I did not have access to the underlying
CfnUserPoolviafromUserPoolIdornode.defaultChild.I was however able to add triggers to a user pool imported via
fromUserPoolIdby using a custom resource:⚠️ Warning about using CustomResource with API Call to
UpdateUserPool⚠️We are using the CustomResource to update the cognito user pool with the api call of
updateUserPool, like https://github.com/aws/aws-cdk/issues/10002#issuecomment-854169838, and other attributes got change for no reason, like seeding a verification email.If you only specify the lambda config, other attribute will be reset to the default one as documented in the API DOC
As you can see, there’s not a big emphasis on it!
I’m trying to do this inside of an amplify project using
amplify add custom. It seems though since amplify at this point can’t deploy assets to S3AwsCustomResourceis not working since they run within a lambda. Whatever I try I end up with an error message when runningamplify pushMy goal is to add the
CustomEmailSendertrigger since it’s not supported by the amplify cli yet.FYI - After adding the triggers with a custom resource, I also had to grant invoke permission:
@skinny85 that worked a treat! Thank you so much 🙇🏻
For anyone else encountering this issue, the solution looks like this:
Hi, I have probably workaround 😃
I am new in AWS but I had same problem with resetting user pool changes to defaults (sending emails). I dealt with it in my project by adding custom resource with lambda which basically do three things:
link: https://github.com/MartinMartinni/aws-shop/blob/main/backend/src/services/user/post-confirmation-trigger/updateUserPool.ts
I know that may not be the best way but worked for me. After that sending emails is working 😃
Is there any way to add the trigger without resetting the others? I can’t import the template