Hello
How do i pass environment variables in a cron job in npx sst
Tried this but does not work
new sst.Cron(this, “bitbucket-scheduler-cron”, {
schedule: "rate(5 minutes)",
job: "src/bitbucket-api/scheduler.main",
environment: {
bitbucketScheduleJobTableName:
this.bitbucketScheduleJobTable.dynamodbTable.tableName,
bitbucketScheduleJobUserIdIndexName: "scheduleuserCreatedDateIndex",
scheduleJobIdIndexName: "jobIdCreatedDateIndex",
bitbucketJobTableName: this.bitbucketJobTable.dynamodbTable.tableName,
bitbucketJobUserIdIndexName: "userCreatedDateIndex",
identifierIndexName: "identifierCreatedDateIndex",
},
});
I also want to set timeout and memory size but it does not work
new sst.Cron(this, “bitbucket-scheduler-cron”, {
schedule: "rate(5 minutes)",
job: "src/bitbucket-api/scheduler.main",
defaultFunctionProps: {
timeout: 900,
memorySize: 1024,
environment: {
bitbucketScheduleJobTableName:
this.bitbucketScheduleJobTable.dynamodbTable.tableName,
bitbucketScheduleJobUserIdIndexName: "scheduleuserCreatedDateIndex",
scheduleJobIdIndexName: "jobIdCreatedDateIndex",
bitbucketJobTableName: this.bitbucketJobTable.dynamodbTable.tableName,
bitbucketJobUserIdIndexName: "userCreatedDateIndex",
identifierIndexName: "identifierCreatedDateIndex",
},
},
});
Instead of using the handler path as the value for “job”, you can pass in a function configuration. This should work:
new sst.Cron(this, "bitbucket-scheduler-cron", {
schedule: "rate(5 minutes)",
job: {
function: {
environment: {
bitbucketScheduleJobTableName: this.bitbucketScheduleJobTable.dynamodbTable.tableName,
bitbucketScheduleJobUserIdIndexName: "scheduleuserCreatedDateIndex",
scheduleJobIdIndexName: "jobIdCreatedDateIndex",
bitbucketJobTableName: this.bitbucketJobTable.dynamodbTable.tableName,
bitbucketJobUserIdIndexName: "userCreatedDateIndex",
identifierIndexName: "identifierCreatedDateIndex",
},
handler: "src/bitbucket-api/scheduler.main",
}
}
});