How can i create a lambda function which is not co...
# sst
m
How can i create a lambda function which is not connected to REST endpoint using SST? I want this function to be called after cognito signup. Using SST default project structure, i created a file called
PostSignup.js
and placed it in
src/
... when i did
npc sst start
, i assumed that this funciton will be created but got the message "no changes". How can i i use SST to do so?
f
Hey @Muhammad Ali, it seems you are trying to setup PostSignup trigger for Cognito User Pool. Can you confirm that?
And if so, can you share how you are creating the User Pool?
m
Yeah, I need to create PostSignup and PostAuth lambdas. PostSignup i need to persist "extra fields" which would be added as part of signup. And PostAuth is needed to insert some extra meta data for accessing specific details. I haven't setup anything yet but want to do it using Incognito. Would prefer if everything can be done via sst so that i don't have to replicate to other regions but given that cognito is global, i don't mind using ui to setup cognito
m
This is super helpful. thanks. one more question. how would i tell which cognito pool to use? also, am i suppose to create cognito pool using ui?
@Frank (i apologize that i had to tag)
f
Hey @Muhammad Ali, if you don’t already have a user pool, it’s always good to create one in code rather than the UI.
Check out this full example on creating an API, authenticating it with Cognito User Pool. https://serverless-stack.com/examples/how-to-add-cognito-authentication-to-a-serverless-api.html
After you get the above example to work, you can then add the triggers. Give it a try!
m
Follow up questions 1. I am using cognito postConfirmation trigger. In the trigger, i am persisting some data to dynamodb. Question is what should i do once i persist data. I tried
return {statusCode: 200}
and got error that unrecognized lambda output error. 2. How can i store utc datetime in iso format in dynamodb. I used this
createdAt: new Date().toISOString,
and got an empty value in dynamodb.
r
1 you need to return the event that was passed to the function. 2 toISOString is a function