Hi, how can I set environment variables and permis...
# help
a
Hi, how can I set environment variables and permissions in Cron Stack? my code keeps showing
Error: Invalid function definition for the "Job" Function
Copy code
import { Cron, Function } from "@serverless-stack/resources";

this.function = new Function(this, 'scheduled', {
            handler: "src/scheduled.main",
            environment: {
                TABLE_NAME: table.tableName,
            }
        })

this.cron = new Cron(this, 'cron', {
            schedule: "cron(0 1 * * ? *)"
            job: {
                function: this.function    
            },
        })
this.cron.attachPermissions([table])
f
For the cron, try this:
Copy code
this.cron = new Cron(this, 'cron', {
            schedule: "cron(0 1 * * ? *)"
            job: this.function
        })
Another way to rewrite all of the above code would be:
Copy code
import { Cron } from "@serverless-stack/resources";

this.cron = new Cron(this, 'cron', {
  schedule: "cron(0 1 * * ? *)"
  job: {
    handler: "src/scheduled.main",
    environment: {
      TABLE_NAME: table.tableName,
    },
    permissions: [table],
  },
})

this.function = this.cron.jobFunction;
a
Thanks!