Type annotations for aiobotocore Step Functions

3.4.0 · active · verified Tue Apr 14

This package provides type annotations for the `aiobotocore` library's Step Functions (SFN) client. It is part of the `mypy-boto3-builder` project, which automatically generates type stubs for all `aiobotocore` services. The versioning of `types-aiobotocore-stepfunctions` aligns with the corresponding `aiobotocore` version, currently 3.4.0. The project maintains an active release cadence, driven by updates to `aiobotocore` and improvements in the `mypy-boto3-builder` itself, ensuring up-to-date type support.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `aiobotocore` with `types-aiobotocore-stepfunctions` to start a Step Functions execution. The `SFNClient` type annotation, enclosed in a `TYPE_CHECKING` block, provides rich type hints and autocomplete for the Step Functions client methods and their parameters and return types. Ensure you have `aiobotocore` also installed.

import asyncio
import os
from typing import TYPE_CHECKING

from aiobotocore.session import get_session

# These imports are only for type checking and will not be present at runtime
if TYPE_CHECKING:
    from types_aiobotocore_stepfunctions.client import SFNClient
    from types_aiobotocore_stepfunctions.type_defs import StartExecutionOutputTypeDef


async def start_step_function_execution(state_machine_arn: str, execution_name: str, input_data: str):
    session = get_session()
    async with session.create_client(
        "stepfunctions",
        region_name=os.environ.get('AWS_REGION', 'us-east-1'),
        aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
        aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET'),
    ) as client:
        # client is implicitly typed as SFNClient by mypy/pyright after installing types-aiobotocore-stepfunctions
        if TYPE_CHECKING:
            client: SFNClient

        print(f"Starting execution '{execution_name}' for state machine '{state_machine_arn}'")
        response: StartExecutionOutputTypeDef = await client.start_execution(
            stateMachineArn=state_machine_arn,
            name=execution_name,
            input=input_data,
        )
        print(f"Execution ARN: {response['executionArn']}")
        print(f"Start Date: {response['startDate']}")


if __name__ == "__main__":
    # Replace with your actual State Machine ARN and desired execution details
    STATE_MACHINE_ARN = os.environ.get('STATE_MACHINE_ARN', 'arn:aws:states:us-east-1:123456789012:stateMachine:MyStateMachine')
    EXECUTION_NAME = os.environ.get('EXECUTION_NAME', 'my-test-execution-123')
    INPUT_DATA = os.environ.get('INPUT_DATA', '{"key": "value"}')

    asyncio.run(start_step_function_execution(STATE_MACHINE_ARN, EXECUTION_NAME, INPUT_DATA))

view raw JSON →