Skip to content

Improve human-in-the-loop with one-click email approval#416

Merged
julianwood merged 2 commits into
aws-samples:mainfrom
YogeshNain2015:improve/human-in-the-loop-one-click-approval
Jun 2, 2026
Merged

Improve human-in-the-loop with one-click email approval#416
julianwood merged 2 commits into
aws-samples:mainfrom
YogeshNain2015:improve/human-in-the-loop-one-click-approval

Conversation

@YogeshNain2015

Copy link
Copy Markdown

Summary

This PR improves the existing human-in-the-loop workflow by replacing the direct SNS waitForTaskToken integration with a Lambda-based approach that enables one-click email approval.

Problem with the current approach

  • The current workflow sends the raw task token via SNS email
  • Reviewers must manually copy the token and call aws stepfunctions send-task-success via CLI
  • Task tokens contain special characters (+, /, =) that break when used in URLs

Architecture

User → Step Functions → Lambda (URL-encodes token) → SNS (email with links) → Reviewer clicks link → API Gateway → Lambda (decodes token, calls SendTaskSuccess) → Step Functions resumes

Related

Issue #, if available:

Description of changes:

  • SendApprovalEmailFunction (Python): URL-encodes the task token using urllib.parse.quote and sends an email via SNS with clickable approve/reject links pointing to an API Gateway endpoint
  • HandleApprovalFunction (Python): Receives the callback from API Gateway, decodes the task token, and calls SendTaskSuccess to resume the workflow
  • API Gateway: REST API with a GET /respond endpoint to handle the email link callbacks
  • State machine: Updated to use lambda:invoke.waitForTaskToken instead of sns:publish.waitForTaskToken
  • Architecture diagram: Added SVG diagram with official AWS service icons showing the complete flow
  • README & example-workflow.json: Updated documentation reflecting the new approach

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Replace the direct SNS waitForTaskToken integration with a Lambda-based
approach that URL-encodes the task token and sends clickable approve/reject
links via email. This eliminates the need for reviewers to manually copy
task tokens and use the AWS CLI.

Changes:
- Add SendApprovalEmailFunction (Python) that URL-encodes the task token
  and publishes an email with approve/reject links via SNS
- Add HandleApprovalFunction (Python) that decodes the token and calls
  SendTaskSuccess to resume the workflow
- Add API Gateway endpoint to handle the approval callback
- Update state machine to use lambda:invoke.waitForTaskToken
- Add architecture diagram (SVG) with official AWS icons
- Update README and example-workflow.json

From aws-samples#401
Comment thread human-in-the-loop/README.md Outdated
# Human in the Loop

This pattern allows you to integrate an human review or approval process into your workflows. Each task sends a message to a SNS topic which sends a notification to a human reviewer or approver by email for example. The workflow then waits until the approver completes their review. Depending on the review outcome a different Lambda function can be invoked.
This pattern allows you to integrate a human review or approval process into your workflows with **one-click email approval**. A Lambda function sends an approval request via SNS email containing clickable approve/reject links. The task token is URL-encoded to ensure special characters don't break the API Gateway callback URL. The workflow pauses until the reviewer clicks a link, which triggers an API Gateway endpoint to resume the Step Functions execution.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This pattern allows you to integrate a human review or approval process into your workflows with **one-click email approval**. A Lambda function sends an approval request via SNS email containing clickable approve/reject links. The task token is URL-encoded to ensure special characters don't break the API Gateway callback URL. The workflow pauses until the reviewer clicks a link, which triggers an API Gateway endpoint to resume the Step Functions execution.
This pattern allows you to integrate a human review or approval process into your workflows with **one-click email approval**. An AWS Lambda function sends an approval request via Amazon SNS email containing clickable approve/reject links. The task token is URL-encoded to ensure special characters don't break the Amazon API Gateway callback URL. The workflow pauses until the reviewer clicks a link, which triggers an API Gateway endpoint to resume the AWS Step Functions execution.

Comment thread human-in-the-loop/template.yaml Outdated
CodeUri: lambda/
Handler: app.handler
Runtime: nodejs24.x
Runtime: nodejs20.x

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you downgrade the Node version?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was doing little test... forgot to change it so reverted it back to 24....

- Keep nodejs24.x runtime for ProcessingLambda (SAM CLI upgrade resolved
  the build issue)

@bfreiberg bfreiberg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for your contribution. Your changes will be merged soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants