serverless: AWS Cognito User Pool triggers support
This is a Feature Proposal
Description
I’d like to be able to create functions that hook into a User Pool for various use-cases such as preSignup, customMessage etc. (which are defined here).
Currently I deploy the functions then manually attach them via AWS Console (although this can probably be automated using the AWS SDK).
I am aware that Lambda event sources are different from Lambda triggers (at least conceptually), but in practice they both seem to be only fired when an event occurs. Therefore, it would be lovely if I could define them in serverless.yml with something as follows:
functions:
preSignup:
handler: handler.preSignup
events:
- cognito-user-pool:
pool: <POOL-ID>
trigger: PreSignUp
Similar or dependent issues:
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 6
- Comments: 20 (20 by maintainers)
Thank you for the greate proposal @hassankhan 😍 That could be super helpful and really useful! I often use
Cognito UserPooltoo, and face the same problem 😅As you say, those triggers are a little different from Lambda event sources, so it may be better to change the syntax to distinguish
eventsfrom Lambda triggers.For example
What do you think? @pmuens @eahefnawy
Awesome!!! 💯 Thank you very much @hassankhan for working on this one! 🥇 And thank you @horike37 for helping out! 💪
Already added the PR to the review list! 🎉
All done and tests passing! 👍 thanks everyone for all your help, hugely appreciated!
The
pool: <POOL_ID>property should also supportRefto reference a user pool defined and created via the resources section.@horike37 I think it would make sense to keep these as
events. It helps keep the cognitive overhead low. As stated by @hassankhanI really agree with this conceptually. Internally at Serverless we’re striving to boil everything down to two simple concepts, events and functions.
That being said, I think this implementation is the most straightforward and familiar.
Ahh thanks, that’s exactly what I was missing 🤦♂️ I’m going to try and add more integration tests, then make a PR 🎉
@horike37 Yep that’s what I thought, doesn’t seem like there’s any other way. Do you have any idea whether the
stringvalues of thetriggerSources are Lambda ARNs?UPDATE: I got an answer on the AWS forums, it is indeed the ARN
@hassankhan maybe, you have to include
triggerSourceinside your handler function as code. So I think we should specify contents of ‘LambdaConfig’ astriggerproperties in serverless.yml.