By using AWS re:Post, you agree to the Terms of Use
/Start_state and End_states for step functions/

Start_state and End_states for step functions


Hi All

All I am trying to do is to create a reusable ambda component where I can pass parameters to the class so that the Lambda can do different things, based on input param.

I am using CDK in python to deploy the stack. I would like to create a parallel stepfunction, where I can pass the same lambda using different param/payload so they can be branches.

I am running the following code:

from aws_cdk import (
    # Duration,
    # aws_sqs as sqs,
    aws_stepfunctions as _stepfunctions,
    aws_stepfunctions_tasks as _stepfunctions_tasks,
    aws_lambda as _lambda,
from constructs import Construct

class LambdaJob(_stepfunctions.StateMachineFragment):

    def __init__(self, parent, id, *, jobTypeParam):
        super().__init__(parent, id)

        existingFunc = _lambda.Function.from_function_arn(self, "ExistingLambdaFunc", function_arn="arn:aws:lambda:us-east-1:95842$$$$$:function:dummyFunction")

        lambda_invoked = _stepfunctions_tasks.LambdaInvoke(self, "someID", lambda_function=existingFunc)
        wait_10_seconds = _stepfunctions.Wait(self, "Wait for 10 seconds",
        self.start_state = wait_10_seconds

class StepfunctionsClasStack(Stack):

    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        test_lambda_1 = LambdaJob(self, "Quick")
        #state_machine = _stepfunctions.StateMachine(self, "TestStateMachine",
        #                                            definition=LambdaJob(self, "Quick"),
        #                                            # role=marketo_role
        #                                            )

However i keep getting the following error:

TypeError: Can't instantiate abstract class LambdaJob with abstract methods end_states, start_state

Any thoughts on what I am doing wrong ? Thanks

1 Answers

Solved by overriding the methods:

        self._start_state = parallel_state#wait_10_seconds

        self._end_states = [chain]#[lambda_invoked]

    def start_state(self):
        return self._start_state

    def end_states(self):
        return self._end_states
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions