Implementation for accessing StepFunctions AWS Step Functions

AWS Step Functions is a web service that enables you to coordinate the components of distributed applications and microservices using visual workflows. You build applications from individual components that each perform a discrete function, or task, allowing you to scale and change applications quickly. Step Functions provides a graphical console to visualize the components of your application as a series of steps. It automatically triggers and tracks each step, and retries when there are errors, so your application executes in order and as expected, every time. Step Functions logs the state of each step, so when things do go wrong, you can diagnose and debug problems quickly.

Step Functions manages the operations and underlying infrastructure for you to ensure your application is available at any scale. You can run tasks on the AWS cloud, on your own servers, or an any system that has access to AWS. Step Functions can be accessed and used with the Step Functions console, the AWS SDKs (included with your Beta release invitation email), or an HTTP API (the subject of this document).

Inheritance: AmazonServiceClient, IAmazonStepFunctions
        static async Task <string> Wait(string arn, TimeSpan wait, TimeSpan max)
        {
            var  startTime      = DateTimeOffset.Now;
            var  client         = new Amazon.StepFunctions.AmazonStepFunctionsClient();
            bool shouldContinue = true;

            while (shouldContinue)
            {
                var result = await client.DescribeExecutionAsync(new DescribeExecutionRequest()
                {
                    ExecutionArn = arn
                });

                Console.WriteLine(result.Status.Value);
                if (result.Status == ExecutionStatus.SUCCEEDED)
                {
                    Console.WriteLine("::set-output name=statemachineexecutionarn::" + result.Output);
                    Console.WriteLine("::set-output name=result::" + result.Output);

                    return(result.Output);
                }
                else if (result.Status == ExecutionStatus.RUNNING)
                {
                    if (DateTimeOffset.Now > startTime.Add(max))
                    {
                        //timed out
                        throw new Exception("The state machine retried the max time");
                    }

                    await Task.Delay(wait);
                }
                else if (result.Status == ExecutionStatus.ABORTED)
                {
                    throw new Exception("State machine aborted ");
                }
                else if (result.Status == ExecutionStatus.FAILED)
                {
                    var history = await client.GetExecutionHistoryAsync(new GetExecutionHistoryRequest()
                    {
                        ExecutionArn         = arn,
                        ReverseOrder         = true,
                        IncludeExecutionData = true
                    });

                    var reason = history.Events
                                 .FirstOrDefault(x => x.ExecutionFailedEventDetails != null)?.ExecutionFailedEventDetails
                                 .Cause ?? "Unknown";

                    throw new Exception("State machine failed. Reason: " + reason);
                }
                else if (result.Status == ExecutionStatus.TIMED_OUT)
                {
                    throw new Exception("State machine timed out ");
                }
            }
            return(string.Empty);
        }
        static Task <StartExecutionResponse> Run(string arn, string name, string input)
        {
            var client = new Amazon.StepFunctions.AmazonStepFunctionsClient();

            return(client.StartExecutionAsync(new StartExecutionRequest()
            {
                Input = input,
                Name = name,
                StateMachineArn = arn
            }
                                              ));
        }