Hello! Does sst work for debugging AWS Step Functi...
# help
j
Hello! Does sst work for debugging AWS Step Functions?
s
It depends on what you mean by debugging step functions. I'm using SST to debug Lambdas in my Step Function workflow
SST doesn't have any constructs for Step Functions. You'd use CDK directly to provision step function workflows, but use the sst.Function wherever you use a LambdaInvoke task
j
Understood! I want to trigger a AWS Step Function from AWS Console and debug the functions from VS Code. Is it possible?
s
You bet!
A quick copy/paste summary of what this would look like, please forgive any typos:
Copy code
# index.ts
import { FunctionStack } from "./FunctionStack";
import { StepFunctionStack } from "./StepFunctionStack";
import { App } from "@serverless-stack/resources";


export default function main(app: App) {

  // Set default runtime for all functions
  app.setDefaultFunctionProps({
    runtime: "nodejs16.x",
    srcPath: "src",
  });

  app.stack(FunctionStack)
     .stack(StepFunctionStack);
}
Copy code
# FunctionStack.ts

import { StackContext, Function } from "@serverless-stack/resources";

export function FunctionStack({ stack, app }: StackContext) {

  const myFunction = new Function(stack, "my-function", {
    handler: "functions/my-function.handler",
  });

  return { myFunction}
}
Copy code
#StepFunctionStack.ts


import { FunctionStack } from "./FunctionStack";
import { StackContext, use } from "@serverless-stack/resources";
import { aws_stepfunctions_tasks as tasks } from "aws-cdk-lib";
import { aws_stepfunctions as sfn } from "aws-cdk-lib";
import { Duration } from "aws-cdk-lib";

export function StepFunctionStack({ stack, app }: StackContext) {
  const { myFunction} = use(FunctionStack);

  const myFunctionTask = new tasks.LambdaInvoke(stack, "MyFunctionTask", {
    lambdaFunction: myFunction,
    // Lambda's result is in the attribute `Payload`
    inputPath: "$",
  });

  // Define next state for manager validation step
  const definition = myFunctionTask
                      .next(...)
                      .next(...)

  const myStateMachine = new sfn.StateMachine(stack, "MyStateMachine", {
    definition,
    stateMachineName: `MyStateMachine`,
    timeout: Duration.seconds(10),
  });

  return {transferStateMachine}
}
j
Thanks @Seth Geoghegan!!!
s
Good luck! I just started working with Step Functions recently, and SST really boosts the productivity.
The Step Functions tooling + SST is an amazing combo
I feel like I'm in the future 😆
f
Thanks for sharing @Seth Geoghegan!