Subscription Onboarding

Orchestrates full tenant onboarding — validation, account creation, billing setup, resource provisioning, activation, and SQS welcome notification.

{
  "Comment": "SaaS tenant subscription onboarding workflow",
  "StartAt": "ValidateSubscription",
  "States": {
    "ValidateSubscription": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Parameters": {
        "FunctionName": "${ValidateSubscriptionFunctionArn}",
        "Payload.$": "$"
      },
      "ResultPath": "$.validation",
      "Retry": [
        {
          "ErrorEquals": [
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException"
          ],
          "IntervalSeconds": 2,
          "MaxAttempts": 3,
          "BackoffRate": 2
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "ResultPath": "$.error",
          "Next": "ValidationFailed"
        }
      ],
      "Next": "IsValidSubscription"
    },
    "IsValidSubscription": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.validation.Payload.isValid",
          "BooleanEquals": true,
          "Next": "CreateTenantAccount"
        }
      ],
      "Default": "ValidationFailed"
    },
    "ValidationFailed": {
      "Type": "Fail",
      "Error": "InvalidSubscription",
      "Cause": "Subscription request failed validation"
    },
    "CreateTenantAccount": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Parameters": {
        "FunctionName": "${CreateAccountFunctionArn}",
        "Payload.$": "$"
      },
      "ResultPath": "$.account",
      "Retry": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "IntervalSeconds": 2,
          "MaxAttempts": 2,
          "BackoffRate": 2
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "ResultPath": "$.error",
          "Next": "OnboardingFailed"
        }
      ],
      "Next": "SetupBilling"
    },
    "SetupBilling": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Parameters": {
        "FunctionName": "${SetupBillingFunctionArn}",
        "Payload.$": "$"
      },
      "ResultPath": "$.billing",
      "Retry": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "IntervalSeconds": 3,
          "MaxAttempts": 2,
          "BackoffRate": 2
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "ResultPath": "$.error",
          "Next": "OnboardingFailed"
        }
      ],
      "Next": "ProvisionResources"
    },
    "ProvisionResources": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Parameters": {
        "FunctionName": "${ProvisionResourcesFunctionArn}",
        "Payload.$": "$"
      },
      "ResultPath": "$.resources",
      "Retry": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 2,
          "BackoffRate": 2
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "ResultPath": "$.error",
          "Next": "OnboardingFailed"
        }
      ],
      "Next": "ActivateSubscription"
    },
    "ActivateSubscription": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Parameters": {
        "FunctionName": "${ActivateSubscriptionFunctionArn}",
        "Payload.$": "$"
      },
      "ResultPath": "$.activation",
      "Retry": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "IntervalSeconds": 2,
          "MaxAttempts": 2,
          "BackoffRate": 2
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "ResultPath": "$.error",
          "Next": "OnboardingFailed"
        }
      ],
      "Next": "SendWelcomeNotification"
    },
    "SendWelcomeNotification": {
      "Type": "Task",
      "Resource": "arn:aws:states:::sqs:sendMessage",
      "Parameters": {
        "QueueUrl": "https://sqs.us-east-1.amazonaws.com/123456789012/subscription-events",
        "MessageBody": {
          "event": "SUBSCRIPTION_ACTIVATED",
          "subscriptionId.$": "$.subscriptionId",
          "tenantId.$": "$.tenantId",
          "plan.$": "$.plan",
          "activatedAt.$": "$.activation.Payload.activatedAt"
        }
      },
      "ResultPath": "$.notification",
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "ResultPath": "$.notificationError",
          "Next": "SubscriptionActivated"
        }
      ],
      "Next": "SubscriptionActivated"
    },
    "SubscriptionActivated": {
      "Type": "Succeed"
    },
    "OnboardingFailed": {
      "Type": "Fail",
      "Error": "OnboardingError",
      "Cause": "Subscription onboarding failed during provisioning"
    }
  }
}
JSON
Expand
100%

SaaS teams can use patterns like this to build reliable, compliant, and scalable automation for payment systems and can test and refine these flows locally with Thrubit to reduce cloud cost and speed up iteration.

Free Trial