Implementing Human Approval Workflows in AWS Step Functions using SNS Notifications and Task Tokens
AI Generated Image

Implementing Human Approval Workflows in AWS Step Functions using SNS Notifications and Task Tokens

Sridhar Chevendra Anup Rajpara

In business environment, organizations often need to incorporate human oversight and approvals into their automated workflows. This can be a challenging task, requiring careful coordination between systems and people. However, with the power of AWS Step Functions, you can build robust, scalable approval processes that seamlessly integrate human decision-making into your operations.

Leveraging AWS Step Functions

AWS Step Functions is a fully managed orchestration service that makes it easy to build and run distributed applications using a visual workflow. In this post, we'll explore how you can utilize Step Functions to create a human approval workflow that is both efficient and reliable.

The Approval Workflow

To illustrate this workflow, let's consider a common business scenario: expense report approvals.

In our example, any employee expense exceeding $500 requires managerial approval. When an employee submits an expense report, the workflow receives a JSON payload containing transaction details and the total expense. The system then automatically triggers an approval request, sending an email to the appropriate manager.

{
  "employeeId": "EMP12345",
  "employeeName": "Jane Doe",
  "expenseReportId": "ER98765",
  "submissionDate": "2024-09-25T14:30:00Z",
  "totalExpense": 750.50,
  "currency": "USD",
  "transactions": [
    {
      "transactionId": "T001",
      "date": "2024-09-20",
      "category": "Travel",
      "description": "Flight to New York",
      "amount": 450.00
    },
    {
      "transactionId": "T002",
      "date": "2024-09-21",
      "category": "Accommodation",
      "description": "Hotel stay - 2 nights",
      "amount": 300.50
    }
  ],
  "approvalRequired": true,
  "approverEmail": "manager@example.com"
}        

At the heart of our solution is the human approval aspect. The workflow begins with an automated task that requires a manual review and sign-off. Using Step Functions, we can define this approval step as a distinct task within the overall process. When this task is reached, the workflow pauses, and a notification is sent to the appropriate stakeholder(s) via Amazon SNS.



Article content
AWS Step Functions Workflow

By using AWS Step Functions' built-in service integrations, you can directly invoke Amazon SNS to send customized email notifications as part of your workflow orchestration. here is the sample Step functions SNS API parameters.

{ 
"Message.$": "States.Format('Greetings {} \n, Approve: \"<<API Gateway URL>>?Type=Approve&Token={}\"  \n\n, Decline: \"<<API Gateway URL>>?Type=Decline&Token={}\"  \n', $.email.body, States.Base64Encode($$.Task.Token), States.Base64Encode($$.Task.Token))",
"Subject.$": "States.Format('Expense Approval – {}', $.employeeName)",
"TopicArn": "<<SNS Topic>>"
}        

This email contains a summary of the expenses and allows the manager to approve or decline the report with a single click, streamlining the approval process and ensuring compliance with company policies.

Asynchronous Callbacks with Task Tokens

To ensure the workflow can resume seamlessly after the manual approval, we'll leverage the asynchronous callback pattern in Step Functions, which utilizes task tokens. When the approval task is reached, the workflow will wait for the human to provide their input. Once the approval is granted, the stakeholder can use the task token to notify Step Functions, allowing the workflow to continue execution based on the approval status(approve/decline).

Article content
Human Approval Work Flow

For additional instructions to test it in your aws account refer GitHub.

Note: All the code and artifacts are developed using Amazon Q Developer.

Benefits of the Approval Workflow

By integrating human approvals into your automated processes using AWS Step Functions, you can unlock several key benefits:

  1. Increased Efficiency: Streamline your operations by automating the majority of the workflow, while still allowing for necessary human oversight.
  2. Enhanced Reliability: Leverage the robust error handling and retry capabilities of Step Functions to ensure your approval process is resilient and dependable.
  3. Improved Visibility: Monitor the progress of your approval workflows in real-time using the Step Functions dashboard and CloudWatch metrics.

Conclusion

Integrating human approvals into automated workflows is vital for important business decisions. With AWS Step Functions, you can easily add manual approval steps for transactions like capital asset purchases, contract approvals, and high-risk operations.

This powerful tool allows you to create scalable and reliable approval processes that enhance efficiency and improve overall operations. By combining automation with human oversight, your organization can maintain control while streamlining processes.


This blog represents my own viewpoints and not of my employer, Amazon Web Services (AWS). All product names, logos, and brands are the property of their respective owners.



Nice write up! I have yet to really explore Step Functions, but you may have just inspired me.

Great article! Sridhar Chevendra If there's an opportunity to enhance it further, it might be useful to: - Add a daily or weekly reminder to act on pending requests, or automatically cancel them after 30 days. - Include the source in email notifications so recipients know where the email originated. Thanks for sharing!

Like
Reply

To view or add a comment, sign in

More articles by Sridhar Chevendra

Explore content categories