AWS Step Functions Data Science SDK

2.3.0 · active · verified Thu Apr 16

The AWS Step Functions Data Science SDK is an open-source Python library that allows data scientists to easily create, visualize, and execute machine learning (ML) workflows using Amazon SageMaker and AWS Step Functions. It enables the orchestration of AWS infrastructure at scale directly from Python code or Jupyter notebooks, abstracting away the need to provision and integrate AWS services separately. The library is currently at version 2.3.0 and maintains an active development and release cadence, with several updates per year.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a simple Pass state, chain it into a workflow, create the workflow on AWS Step Functions, and then execute it with sample input. It includes placeholders for AWS IAM roles and credentials, which must be configured in your environment or AWS CLI for actual deployment and execution.

import os
from stepfunctions.workflow import Workflow
from stepfunctions.steps import Pass, Chain

# Dummy AWS credentials for local testing/placeholder - replace with actual credentials/roles in production
# Ensure your environment has AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN (optional) and AWS_REGION set
# or your ~/.aws/credentials and ~/.aws/config are configured.
# For actual deployment, you'd typically use an IAM role.

# Define a simple Pass state
pass_step = Pass(
    state_id='MyPassState',
    parameters={
        'input_data.$': '$'
    }
)

# Create a workflow
workflow = Workflow(
    name='MySimpleWorkflow',
    definition=pass_step,
    role=os.environ.get('STEPFUNCTIONS_EXECUTION_ROLE_ARN', 'arn:aws:iam::123456789012:role/FakeStepFunctionsExecutionRole') # Replace with your IAM Role ARN
)

try:
    # Create the workflow on AWS Step Functions
    workflow.create()
    print(f"Workflow '{workflow.name}' created successfully.")

    # Execute the workflow with sample input
    execution = workflow.execute(inputs={'message': 'Hello from Step Functions SDK!'})
    print(f"Workflow execution started with ARN: {execution.execution_arn}")

    # Wait for execution to complete and print output
    execution.wait_for_completion()
    print(f"Execution finished. Output: {execution.get_output()}")

    # Clean up (optional, for real workflows, you might not delete immediately)
    # workflow.delete()
    # print(f"Workflow '{workflow.name}' deleted.")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure your AWS credentials are configured and the IAM role ARN is valid and has necessary permissions.")
    print("You can define the IAM role ARN as an environment variable STEPFUNCTIONS_EXECUTION_ROLE_ARN.")

view raw JSON →