Orkestra helps with the orchestration of scheduled cron-like tasks,
similar to Airflow, but being built on top of Step Functions
means workflows can be invoked by any number of events in the AWS Ecosystem.
In this example, we'll create a workflow that can be asynchronously triggered via an HTTP call to API Gateway.
Info
We'll write our API using a modern web framework, FastAPI which uses type annotations and pydantic to produce automatic API
documentation and json serialization/deserialization.
We use Mangum to handle the translation of API Gateway calls to ASGI and vice-versa.
FastAPI is built on top of Starlette which implements the ASGI protocol to transate HTTP to Python objects and vice-versa.
importosfromaws_cdkimportaws_apigatewayasapigwfromaws_cdkimportaws_lambdafromaws_cdkimportaws_lambda_pythonfromaws_cdkimportaws_stepfunctionsassfnfromaws_cdkimportcoreascdkfromexamples.restimportinput_orderclassRestExample(cdk.Stack):def__init__(self,scope,id,**kwargs):super().__init__(scope,id,**kwargs)state_machine:sfn.StateMachinestate_machine=input_order.state_machine(self,state_machine_name="process_order_example",)cdk.CfnOutput(self,"rest_invoked_sfn",value=state_machine.state_machine_arn,)stage_name=os.environ["ENVIRONMENT"]fn=aws_lambda_python.PythonFunction(self,"example_api_handler",entry="./examples/",index="rest.py",runtime=aws_lambda.Runtime.PYTHON_3_8,environment={"STATE_MACHINE_ARN":state_machine.state_machine_arn,"ROOT_PATH":stage_name,},)state_machine.grant_start_execution(fn)api=apigw.LambdaRestApi(self,"example_api",handler=fn,deploy_options=apigw.StageOptions(stage_name=stage_name),)fn.add_environment("ROOT_PATH",stage_name)# we can still schedule as normalinput_order.schedule(self,state_machine_name="schedule_rest_example",)
This file would exist in the same directory as your lambdas' module