https://serverless-stack.com/ logo
#help
Title
# help
a

Adrian Schweizer

03/23/2022, 9:36 PM
how can I pass values to a Cron's environment? I'm trying to make a job that works with the DB, and thus I need to pass in the table names. Tried it like this, but doesn't seem to work:
Copy code
export default class CronStack extends sst.Stack {
   constructor(scope, id, props) {
      super(scope, id, props);

      const { tableNames } = props;

      new sst.Cron(this, "ReminderMail", {
         schedule: "rate(1 minute)",
         job: "src/participations/mailReminder.main",
         jobProps: {
            environment: {
               ...tableNames,
               // more env vars
            },
         },
      });
   }
}
r

Ross Coundon

03/23/2022, 9:38 PM
You can define your function with env vars, and then pass that as the value to the job property
f

Frank

03/23/2022, 9:39 PM
@Ross Coundon + 1. Yeah try something like this:
Copy code
new sst.Cron(this, "ReminderMail", {
         schedule: "rate(1 minute)",
         job: {
           function: {
             handler: "src/participations/mailReminder.main",
             environment: {
               ...tableNames,
            },
         },
      });
a

Adrian Schweizer

03/23/2022, 9:39 PM
ah, very cool, thx guys
btw, how is this knowledge best acquired? I looked up the sst Cron tutorials ans API doc, but didn't really pick that possibility up
ah, never mind, I see it now, it's in the API doc after all
I just didn't understand what
_Type_ : FunctionDefinition | CronJobProps
really means