SOLVED - See thread. I had the trigger written out...
# help
d
SOLVED - See thread. I had the trigger written out incorrectly. When someone signs up for my app I want to create a row in the dynamodb table for them. Seems like the use case for a postConfirmation trigger. Here’s what I’ve set up.
Copy code
// Create a HTTP API
    this.api = new sst.Api(this, "Api", {
      defaultAuthorizationType: "AWS_IAM",
      defaultFunctionProps: {
        environment: {
          TABLE_NAME: customersTable.tableName,
        },
      },
      // prettier-ignore
      routes: {
        "POST     /profile":         "src/profile/createProfile.main", // this isn't really doing anything but I thought maybe it would help
     }
   })

   this.api.attachPermissions([customersTable]);

   const auth = new sst.Auth(this, "Auth", {
      cognito: {
        userPool: {
          signInAliases: { email: true },
        },
        defaultFunctionProps: {
          timeout: 20,
          environment: { TABLE_NAME: customersTable.tableName },
          permissions: [customersTable],
        },
        lambdaTriggers: {
          postAuthentication: "src/profile/createProfile.main",
        },
      },
    });
Really all that happens in
createProfile.main
right now is a console log. import handler from “../utils/handler”; import dynamoDb from “../utils/dynamodb”;
Copy code
export const main = handler(async (event) => {
  console.log("[44m%s[0m", `--(event--${JSON.stringify(event)}-----`);
But I can’t see that on signUp. Which i guess sorta makes sense because that’s a service that’s outside of Live Lambda development maybe? How can I log out the event so I can figure out what I want in my table?
r
On my phone at the moment but I think it's the postConfirmation trigger you need
d
Yes that’s more accurate to what I want. Updated! How to debug the code remains an issue. I’m just gonna try to update the dynamo table and see what happens 🦆
b
You can debug postConfirmation triggers locally , i have a post confirmation trigger setup in a similar way to save the user in DynamoDB here if that helps you any - https://github.com/brossdev/serverless-federated-gql-api/blob/main/core/stacks/Gateway.ts When i sign up via the react app using the “local” api endpoint the post confirmation fires.
d
That likely means I’m doing something wrong then!
Thanks the both of you. I’m going to try pulling out my create function from the API and see if that helps
I’ve found my function in the console. However, it’s not being hit. I suspect this has something to do with me using Amplify maybe. I’ll have to keep hunting I guess
Hey hey it’s sorta working what i needed was to edit the lambda as a trigger not a lambdaTrigger
Copy code
const auth = new sst.Auth(this, "Auth", {
      cognito: {
        userPool: {
          signInAliases: { email: true },
        },
        defaultFunctionProps: {
          timeout: 20,
          environment: { TABLE_NAME: customersTable.tableName },
          permissions: [customersTable],
        },
        triggers: {
          postConfirmation: "src/createProfile.main",
        },
      },
    });
Now I’m getting a new error but the database is getting the profile added so 🎉
The final issue was sign-in failing in the post confirmation trigger in the UI. In my lambda all I had to do was return context.done. I don’t know but understanding it will be a problem for a future day
Copy code
await dynamoDb.put(params);

    // this fails without the follow return in the trigger.
    return context.done(null, event);
Thank you both so much!!
r
Ah, yes. You have to Signal in your hook that the confirmation process implemented in the lambda was successful so that the final part of the cognito flow continues after your hook completes