Does SST support AWS Step Function? I want to trig...
# help
j
Does SST support AWS Step Function? I want to trigger a lambda function only once after 5 days, is it possible with SST?
r
You could achieve that with a cron, would probably be simpler
j
The problem is I want it to run only when the user click on a button. If I use cron, I have to do this
Copy code
new Cron(this, "Cron", {
  schedule: "rate(1 minute)",
  job: "src/lambda.main",
});
which is not dynamic. Also with cron, does it destroy itself? There might be a scenario where 10,000 users click on the button. I don't want 10,000 crons running forever.
t
Hey I'm building something to do this, with dynamodb and sqs. Happy to share access to the code so you can copy it. Send me a DM if you are interested
r
Ah, I see, I thought you meant it would only ever run once, as opposed to, it only ever runs once in response to an event, from a particular user interaction
j
Thanks Thomas. Hmm, it seems like it's a'lot of work when I need to involve dynamodb and sqs... I'll DM later haha. In theory, it looks simple enough in serverless framework via serverless.yml where you just add
"Wait": 60
. Hmm...
t
thats with step functions right? The downside with that is the scalability, if you have lots of users the bill could be quite a bit
where as dynamodb and sqs are super cheap
but agreed its a bit fiddly 😄 I’m building it as a micro saas but its still early days
j
Ah, Im ok with step functions because we don't have many users
f
@Jack Tan if u decide to go with Step Functions. Check out this example https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions-readme.html#example
In this example, u can create
submitLambda
and
getStatusLambda
like this:
Copy code
const submitLambda = new sst.Function(this, "Submit", {
  handler: "src/submit",
});
Let me know if that works for u.
j
@Frank Is there a way to trigger the step function on user input? Something like this?
Copy code
'GET /test': new sfn.StateMachine(this, 'StateMachine', {
        definition: sWait
          .next(sHello)
          .next(
            new sfn.Choice(this, 'Job Approved?')
              .when(
                sfn.Condition.stringEquals('$.status', 'Approved'),
                sSuccess,
              )
              .otherwise(sFailed),
          ),
      }),
Actually, I'm just going to run a cron job and do a for loop to check everything. When user clicks a button it will save the info into dynamodb. This step function documentation is quite sparse..