Hey guys, nice to be here. Currently trying out SS...
# general
i
Hey guys, nice to be here. Currently trying out SST for a prototype. Was wondering if it's possible to leverage AWS step functions? https://www.serverless.com/plugins/serverless-step-functions
f
CDK has a really nice way of defining step functions. Some examples here in there doc - https://docs.aws.amazon.com/cdk/api/latest/docs/aws-stepfunctions-readme.html And replace
lambda.Function
with
sst.Function
Here is an example https://docs.serverless-stack.com/migrating-from-serverless-framework#serverless-step-functions (
Let me know if you got any questions
i
Amazing, thanks ❤️
g
hello @FrankI have one problem when replacing
lambda.Function
with
sst.Function
, it seems a conflict type, here’s the code:
Copy code
import * as sst     from '@serverless-stack/resources';
import * as sfn     from '@aws-cdk/aws-stepfunctions';
import * as tasks   from '@aws-cdk/aws-stepfunctions-tasks';

export class ReservationLifecycleSM extends sfn.StateMachine {
    constructor(stack: sst.Stack, app: <http://sst.App|sst.App>, id: string) {
        // Define each state
        const sWait = new sfn.Wait(stack, 'Wait', {
            time: sfn.WaitTime.duration(300),
        });
        const sHello = new tasks.LambdaInvoke(stack, 'Hello', {
            lambdaFunction: new sst.Function(stack, 'Hello', 'hello.main'),
        });

        const sFailed = new sfn.Fail(stack, 'Failed');

        const sSuccess = new sfn.Succeed(stack, 'Success');

        super (stack, id, {
            definition: sWait
                .next(sHello)
                .next(
                    new sfn.Choice(stack, 'Job Approved?')
                        .when(sfn.Condition.stringEquals('$.status', 'Approved'), sSuccess)
                        .otherwise(sFailed)
                ),
        });
    }
}
I copy and paste your example (there is a little change to adapt it to my project structure)
f
@gio Let me give that a try.
Can you try changing
Copy code
lambdaFunction: new sst.Function(stack, 'Hello', 'hello.main')
to
Copy code
lambdaFunction: new sst.Function(stack, 'Hello', {
  handler: 'hello.main'
})
g
yes it solves the second error but the first one still give me error
f
hmm.. can I see the dependency section of your package.json?
g
Copy code
{
  "name": "myproj",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "test": "sst test",
    "start": "sst start",
    "build": "sst build",
    "deploy": "sst deploy",
    "remove": "sst remove"
  },
  "devDependencies": {
    "@aws-cdk/assert": "1.98.0",
    "@types/aws-lambda": "^8.10.70",
    "@types/lodash": "^4.14.168"
  },
  "dependencies": {
    "@aws-cdk/assert": "1.98.0",
    "@aws-cdk/aws-apigateway": "1.98.0",
    "@aws-cdk/aws-apigatewayv2": "1.98.0",
    "@aws-cdk/aws-apigatewayv2-integrations": "1.98.0",
    "@aws-cdk/aws-certificatemanager": "1.98.0",
    "@aws-cdk/aws-cognito": "1.98.0",
    "@aws-cdk/aws-dynamodb": "1.98.0",
    "@aws-cdk/aws-iam": "1.98.0",
    "@aws-cdk/aws-lambda": "1.98.0",
    "@aws-cdk/aws-route53": "1.98.0",
    "@aws-cdk/core": "1.98.0",
    "@serverless-stack/cli": "0.16.0",
    "@serverless-stack/resources": "0.16.0",
    "axios": "^0.21.1",
    "date-fns": "^2.21.1",
    "date-fns-tz": "^1.1.4",
    "lodash": "^4.17.21"
  }
}
f
I don’t see
@aws-cdk/aws-stepfunctions
and
@aws-cdk/aws-stepfunctions-tasks
Can you run
npx run add-cdk @aws-cdk/aws-stepfunctions @aws-cdk/aws-stepfunctions-tasks
to add them to your package.json?
g
😝 yes sorry Frank, I forgot to install dependencies in the package.json, now it works ✌️ thank you so much
f
Nice! 👍