Back to Step Functions

cancelScheduledFlow

Intermediate

Cancels and removes previously scheduled workflows that are no longer needed, preventing future executions and cleaning up resources.

overview

The cancelScheduledFlow function allows you to stop and remove previously scheduled workflows that are no longer needed. This function is essential for cleaning up one-time schedules after completion or canceling recurring schedules that are no longer required.

Cancel and remove scheduled workflow executions, preventing future runs of the specified scheduled flow while maintaining proper resource management and system cleanliness.

Essential Cleanup: This function is particularly useful for creating self-managing workflows that can clean up their own schedules when tasks are completed or conditions change, preventing unnecessary resource usage and maintaining a clean scheduling environment.

Key Benefits

Resource Management

  • Prevent unnecessary future executions
  • Clean up completed one-time schedules
  • Optimize system performance
  • Reduce resource consumption

Workflow Control

  • Dynamic schedule management
  • Condition-based cancellation logic
  • Self-managing workflows
  • Intelligent cleanup automation

input_parameters

ParameterTypeRequiredDescription
target_flow_idstringOptionalSpecific scheduled flow ID to cancel
selfbooleanOptionalIf true, cancels the current workflow's own scheduled flow

Return Format

The cancelScheduledFlow function returns a simple completion confirmation:

Cancellation Confirmation

Parameter Note: You must provide either target_flow_id or set self to true. Both parameters are optional individually, but one must be specified for the function to work.

Usage Patterns

Cancel Current Workflow's Schedule

Cancel the schedule created by the current workflow execution

Primary Use Case: Use when the current workflow wants to cancel its own scheduled execution, typically at the end of a one-time scheduled task

Cancel Specific Scheduled Flow

Cancel a specific scheduled flow using its unique ID

Primary Use Case: Use when you have the specific scheduled flow ID and want to cancel that particular schedule from any workflow

Security and Authorization

The cancelScheduledFlow function includes important security measures to protect scheduled flows from unauthorized cancellation:

Ownership Validation

Ensures only the creator of a scheduled flow can cancel it

  • Only the user who created the scheduled flow can cancel it
  • Attempting to cancel another user's scheduled flow results in an authorization error
  • The function validates ownership before performing any cancellation operations

Access Control

End users only need permissions for your main workflow - they don't need access to the invoked workflows

  • Users can only access and manage their own scheduled flows
  • No ability to cancel other users' scheduled workflows
  • Secure schedule management with proper access controls

Usage Examples

Conditional Schedule Cancellation

Using handleConditional to determine when to cancel schedules based on task completion:

Task Completion Cancellation

Self-Managing Workflow

Workflows that automatically clean up their own schedules after completing their purpose:

Document Expiration Reminder

Temporary Monitoring with Cancellation

Set up monitoring that automatically stops when conditions are met:

System Health Monitoring

Schedule Cleanup Patterns

Proper cleanup of one-time schedules after completion:

Maintenance Schedule Cleanup

Conditional Schedule Management

Managing schedules based on external conditions and data changes:

Project Status-Based Cancellation

Best Practices

Resource Cleanup

Maintain system efficiency by properly cleaning up unnecessary scheduled flows.

  • Cancel completed one-time schedules to free up system resources
  • Clean up obsolete recurring schedules that are no longer needed
  • Prevent unnecessary resource usage from abandoned schedules
  • Maintain a clean scheduling environment

Conditional Cancellation

Implement intelligent schedule management based on changing conditions and requirements.

  • Use conditions to determine when schedules should be cancelled
  • Implement smart schedule management logic
  • Cancel schedules when business conditions change
  • Combine with handleConditional for sophisticated decision logic

Schedule Lifecycle Management

Properly manage the entire lifecycle of scheduled flows from creation to completion.

  • Track schedule IDs appropriately for later cancellation
  • Implement proper cleanup logic in workflows
  • Handle schedule completion gracefully
  • Monitor active schedules regularly through the Scheduled tab

Error Prevention

Prevent errors and ensure reliable schedule cancellation operations.

  • Verify schedule exists before attempting cancellation
  • Handle cancellation failures gracefully
  • Use the appropriate cancellation method (self vs target_flow_id)
  • Document schedule dependencies and cleanup requirements

Related Functions

These functions work together with cancelScheduledFlow for comprehensive schedule management and automation: