I need some help with setting up my cognito. Is th...
# help
j
I need some help with setting up my cognito. Is there a proper way to expose
environment
variables to my
preTokenGeneration
and
postAuthentication
handlers? I’m forced to use the old(?) handler interface
a
you mean so that your handlers can access cognito?
if so, just define a policy in the api stack where those handlers routes are set up and attach it to the api stack there
although, hmmm, I'm not sure it's even needed...shouldn't that trigger setup automatically generate some roles that allow it?
if it's just feeding other unrelated params over env to the handlers, you'd do that in api stack where the routes for the handlers are in
Copy code
this.api = new sst.Api(this, "Api", {
         defaultFunctionProps: {
            environment: {
               MY_VAR: "WHATEVER",
            },
m
You can add can use a function type or function props for the triggers.
Copy code
preAuthentication: {
        handler: "src/preAuthentication.main",
        timeout: 10,
        environment: { bucketName: bucket.bucketName },
        permissions: [bucket],
      },
https://docs.serverless-stack.com/constructs/Auth#using-the-full-config-for-a-trigger
f
Thanks guys!
@Jett Robin Andres and if you want to expose environment to all ur triggers, do this:
Copy code
this.auth = new sst.Auth(this, "Auth", {
  cognito: {
    userPool: ...,
    defaultFunctionProps: {
      environment: {
        ENV_VAR_A: ...,
        ENV_VAR_B: ...,
      },
    },
    triggers: ...,
  },
});
j
@Mike McCall’s solution did the trick. Thanks a lot guys!
@Frank that’s freakin neat! I’ll take note of that in the future