# yaml-language-server: $schema=../../../schemas/@aws-mdaa/dataops-stepfunction.json
# (Required) Name of the Data Ops Project
# Name the project the resources of which will be used by this workflow.
# Other resources within the project can be referenced in the workflow config using
# the "project:" prefix on the config value.
projectName: hda-project
# List of step function definitions
stepfunctionDefinitions:
  - stateMachineName: file-processor
    # State Machine Type can be STANDARD or EXPRESS. Refer https://docs.aws.amazon.com/step-functions/latest/dg/concepts-standard-vs-express.html
    stateMachineType: STANDARD
    # ARN of role that will be used to execute the step function.
    # Can be specified as string or SSM parameter in format {{resolve:ssm/path/to/ssm/parameter}}
    stateMachineExecutionRole: ssm-org:/dataops/generated-role/file-processor-role/arn
    # Optional. Number of days the Logs will be retained in Cloudwatch.
    # Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653, and 0.
    # If you specify 0, the events in the log group are always retained and never expire.
    # Default, if property not specified, is 731 days.
    logGroupRetentionDays: 0
    # Required. true or false. Enable or disable logging execution data e.g. parameter values etc.
    logExecutionData: false
    # Integration with Event Bridge for the purpose
    # of triggering this function with Event Bridge rules
    eventBridge:
      # Number of times Event Bridge will attempt to trigger this workflow
      # before sending event to DLQ.
      retryAttempts: 1
      # The max age of an event before Event Bridges sends it to DLQ.
      maxEventAgeSeconds: 60
      eventBridgeRules:
        file-processor-scheduler:
          description: "file processor scheduler"
          # (Optional) - Rules can be scheduled using a crontab expression
          scheduleExpression: "cron(0 {{context:file_processor_event_bridge_trigger_hour}} * * ? *)"
          # (Optional) - If specified, this input will be passed as the event payload to the function.
          # If not specified, the matched event payload will be passed as input.
          input:
            refresh_cadence: "{{context:file_processor_event_bridge_trigger_rate}}_day"
    # The rawStepFunctionDef is Amazon States Language (ASL) JSON exported or copied from AWS Console.
    # Environment specific attributes can be specified as SSM Parameters in format {{resolve:ssm:/path/to/ssm/parameter}}
    rawStepFunctionDef:
      {
        "Comment": "Raw file processor",
        "StartAt": "Batch Generator Lambda",
        "States": {
          "Batch Generator Lambda": {
            "Type": "Task",
            "Resource": "arn:aws:states:::lambda:invoke",
            "OutputPath": "$.Payload",
            "Parameters": {
              "Payload.$": "$",
              "FunctionName": "{{ssm-domain:/hda-function/lambda/batch-generator/name}}"
            },
            "Retry": [
              {
                "ErrorEquals": [
                  "Lambda.ServiceException",
                  "Lambda.AWSLambdaException",
                  "Lambda.SdkClientException"
                ],
                "IntervalSeconds": 2,
                "MaxAttempts": 2,
                "BackoffRate": 2
              }
            ],
            "Next": "File Batches"
          },
          "File Batches": {
            "Type": "Map",
            "End": true,
            "Iterator": {
              "StartAt": "File Processor Trigger Lambda",
              "States": {
                "File Processor Trigger Lambda": {
                  "Type": "Task",
                  "Resource": "arn:aws:states:::lambda:invoke",
                  "OutputPath": "$.Payload",
                  "Parameters": {
                    "Payload.$": "$",
                    "FunctionName": "{{ssm-domain:/hda-function/lambda/file_processor_trigger/name}}"
                  },
                  "Retry": [
                    {
                      "ErrorEquals": [
                        "Lambda.ServiceException",
                        "Lambda.AWSLambdaException",
                        "Lambda.SdkClientException"
                      ],
                      "IntervalSeconds": 2,
                      "MaxAttempts": 2,
                      "BackoffRate": 2
                    }
                  ],
                  "End": true
                }
              }
            },
            "ItemsPath": "$.Items",
            "MaxConcurrency": 5
          }
        }
      }
  - stateMachineName: transformation-jobs
    # State Machine Type can be STANDARD or EXPRESS. Refer https://docs.aws.amazon.com/step-functions/latest/dg/concepts-standard-vs-express.html
    stateMachineType: STANDARD
    # ARN of role that will be used to execute the step function.
    # Can be specified as string or SSM parameter in format {{resolve:ssm/path/to/ssm/parameter}}
    stateMachineExecutionRole: ssm-org:/dataops/generated-role/transformation-role/arn
    # Optional. Number of days the Logs will be retained in Cloudwatch.
    # Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653, and 0.
    # If you specify 0, the events in the log group are always retained and never expire.
    # Default, if property not specified, is 731 days.
    logGroupRetentionDays: 0
    # Required. true or false. Enable or disable logging execution data e.g. parameter values etc.
    logExecutionData: false
    # Integration with Event Bridge for the purpose
    # of triggering this function with Event Bridge rules
    eventBridge:
      # Number of times Event Bridge will attempt to trigger this workflow
      # before sending event to DLQ.
      retryAttempts: 1
      # The max age of an event before Event Bridges sends it to DLQ.
      maxEventAgeSeconds: 60
      eventBridgeRules:
        transformation-scheduler:
          description: "transformation scheduler"
          # (Optional) - Rules can be scheduled using a crontab expression
          scheduleExpression: "cron(0 {{context:transformation_event_bridge_trigger_hour}} * * ? *)"
          # (Optional) - If specified, this input will be passed as the event payload to the function.
          # If not specified, the matched event payload will be passed as input.
          input:
            refresh_cadence: "{{context:transformation_event_bridge_trigger_rate}}_day"
    # The rawStepFunctionDef is Amazon States Language (ASL) JSON exported or copied from AWS Console.
    # Environment specific attributes can be specified as SSM Parameters in format {{resolve:ssm:/path/to/ssm/parameter}}
    rawStepFunctionDef:
      {
        "Comment": "Transformation job workflow",
        "StartAt": "ParallelRun",
        "States": {
          "ParallelRun": {
            "Type": "Parallel",
            "End": true,
            "Branches": [{
              "StartAt": "VitalsJob",
              "States": {
                "VitalsJob": {
                  "Type": "Task",
                  "Resource": "arn:aws:states:::glue:startJobRun",
                  "Parameters": {
                    "JobName": "project:job/name/vitals-transformation-glue-job"
                  },
                  "End": true
                }
              }
            },
              {
                "StartAt": "SurveysJob",
                "States": {
                  "SurveysJob": {
                    "Type": "Task",
                    "Resource": "arn:aws:states:::glue:startJobRun",
                    "Parameters": {
                      "JobName": "project:job/name/surveys-transformation-glue-job"
                    },
                    "End": true
                  }
                }
              }
            ]
          }
        }
      }