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

Jack Tan

03/23/2022, 9:14 AM
Does SST support AWS Step Function? I want to trigger a lambda function only once after 5 days, is it possible with SST?
r

Ross Coundon

03/23/2022, 9:15 AM
You could achieve that with a cron, would probably be simpler
j

Jack Tan

03/23/2022, 9:20 AM
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

Thomas Ankcorn

03/23/2022, 9:23 AM
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

Ross Coundon

03/23/2022, 9:31 AM
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

Jack Tan

03/23/2022, 9:36 AM
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

Thomas Ankcorn

03/23/2022, 9:41 AM
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

Jack Tan

03/23/2022, 9:42 AM
Ah, Im ok with step functions because we don't have many users
f

Frank

03/23/2022, 5:21 PM
@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

Jack Tan

03/24/2022, 12:56 AM
@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..
10 Views