Skip to content

create_state_machine

create_state_machine(
    name: Name,
    definition: Definition,
    role_arn: Arn,
    *,
    config_overrides: Optional[SFNClientConfig] = None,
    type: Optional[StateMachineType] = None,
    logging_configuration: Optional[LoggingConfiguration] = None,
    tags: Optional[TagList] = None,
    tracing_configuration: Optional[TracingConfiguration] = None,
    publish: Optional[Publish] = None,
    version_description: Optional[VersionDescription] = None,
    encryption_configuration: Optional[EncryptionConfiguration] = None,
) -> CreateStateMachineOutput

Creates a state machine. A state machine consists of a collection of states that can do work (Task states), determine to which states to transition next (Choice states), stop an execution with an error (Fail states), and so on. State machines are specified using a JSON-based, structured language. For more information, see Amazon States Language in the Step Functions User Guide.

If you set the publish parameter of this API action to true, it publishes version 1 as the first revision of the state machine.

For additional control over security, you can encrypt your data using a customer-managed key for Step Functions state machines. You can configure a symmetric KMS key and data key reuse period when creating or updating a State Machine. The execution history and state machine definition will be encrypted with the key applied to the State Machine.

This operation is eventually consistent. The results are best effort and may not reflect very recent updates and changes.

CreateStateMachine is an idempotent API. Subsequent requests won’t create a duplicate resource if it was already created. CreateStateMachine's idempotency check is based on the state machine name, definition, type, LoggingConfiguration, TracingConfiguration, and EncryptionConfiguration The check is also based on the publish and versionDescription parameters. If a following request has a different roleArn or tags, Step Functions will ignore these differences and treat it as an idempotent request of the previous. In this case, roleArn and tags will not be updated, even if they are different.

Parameters:

  • name (Name) –

    The name of the state machine.

    A name must not contain:

    • white space

    • brackets < > { } [ ]

    • wildcard characters ? *

    • special characters " # % \ ^ | ~ ` $ & , ; : /

    • control characters (U+0000-001F, U+007F-009F, U+FFFE-FFFF)

    • surrogates (U+D800-DFFF)

    • invalid characters ( U+10FFFF)

    To enable logging with CloudWatch Logs, the name should only contain 0-9, A-Z, a-z, - and _.

  • definition (Definition) –

    The Amazon States Language definition of the state machine. See Amazon States Language.

  • role_arn (Arn) –

    The Amazon Resource Name (ARN) of the IAM role to use for this state machine.

  • type (Optional[StateMachineType], default: None ) –

    Determines whether a Standard or Express state machine is created. The default is STANDARD. You cannot update the type of a state machine once it has been created.

  • logging_configuration (Optional[LoggingConfiguration], default: None ) –

    Defines what execution history events are logged and where they are logged.

    By default, the level is set to OFF. For more information see Log Levels in the Step Functions User Guide.

  • tags (Optional[TagList], default: None ) –

    Tags to be added when creating a state machine.

    An array of key-value pairs. For more information, see Using Cost Allocation Tags in the Amazon Web Services Billing and Cost Management User Guide, and Controlling Access Using IAM Tags.

    Tags may only contain Unicode letters, digits, white space, or these symbols: _ . : / = + - @.

  • tracing_configuration (Optional[TracingConfiguration], default: None ) –

    Selects whether X-Ray tracing is enabled.

  • publish (Optional[Publish], default: None ) –

    Set to true to publish the first version of the state machine during creation. The default is false.

  • version_description (Optional[VersionDescription], default: None ) –

    Sets description about the state machine version. You can only set the description if the publish parameter is set to true. Otherwise, if you set versionDescription, but publish to false, this API action throws ValidationException.

  • encryption_configuration (Optional[EncryptionConfiguration], default: None ) –

    Settings to configure server-side encryption.

Raises:

Source code in docs_src/capo_sfn/_services/sfn.py
def create_state_machine(
    self,
    name: "capo_sfn.types.name.Name",
    definition: "capo_sfn.types.definition.Definition",
    role_arn: "capo_sfn.types.arn.Arn",
    *,
    config_overrides: Optional[SFNClientConfig] = None,
    type: Optional["capo_sfn.types.state_machine_type.StateMachineType"] = None,
    logging_configuration: Optional[
        "capo_sfn.types.logging_configuration.LoggingConfiguration"
    ] = None,
    tags: Optional["capo_sfn.types.tag_list.TagList"] = None,
    tracing_configuration: Optional[
        "capo_sfn.types.tracing_configuration.TracingConfiguration"
    ] = None,
    publish: Optional["capo_sfn.types.publish.Publish"] = None,
    version_description: Optional[
        "capo_sfn.types.version_description.VersionDescription"
    ] = None,
    encryption_configuration: Optional[
        "capo_sfn.types.encryption_configuration.EncryptionConfiguration"
    ] = None,
) -> "capo_sfn.types.create_state_machine_output.CreateStateMachineOutput":
    r"""<p>Creates a state machine. A state machine consists of a collection of states that can do work (<code>Task</code> states), determine to which states to transition next (<code>Choice</code> states), stop an execution with an error (<code>Fail</code> states), and so on. State machines are specified using a JSON-based, structured language. For more information, see <a href="https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html">Amazon States Language</a> in the Step Functions User Guide.</p> <p>If you set the <code>publish</code> parameter of this API action to <code>true</code>, it publishes version <code>1</code> as the first revision of the state machine.</p> <p> For additional control over security, you can encrypt your data using a <b>customer-managed key</b> for Step Functions state machines. You can configure a symmetric KMS key and data key reuse period when creating or updating a <b>State Machine</b>. The execution history and state machine definition will be encrypted with the key applied to the State Machine. </p> <note> <p>This operation is eventually consistent. The results are best effort and may not reflect very recent updates and changes.</p> </note> <note> <p> <code>CreateStateMachine</code> is an idempotent API. Subsequent requests won’t create a duplicate resource if it was already created. <code>CreateStateMachine</code>'s idempotency check is based on the state machine <code>name</code>, <code>definition</code>, <code>type</code>, <code>LoggingConfiguration</code>, <code>TracingConfiguration</code>, and <code>EncryptionConfiguration</code> The check is also based on the <code>publish</code> and <code>versionDescription</code> parameters. If a following request has a different <code>roleArn</code> or <code>tags</code>, Step Functions will ignore these differences and treat it as an idempotent request of the previous. In this case, <code>roleArn</code> and <code>tags</code> will not be updated, even if they are different.</p> </note>

    Args:
        name: <p>The name of the state machine. </p> <p>A name must <i>not</i> contain:</p> <ul> <li> <p>white space</p> </li> <li> <p>brackets <code>< > { } [ ]</code> </p> </li> <li> <p>wildcard characters <code>? *</code> </p> </li> <li> <p>special characters <code>" # % \ ^ | ~ ` $ & , ; : /</code> </p> </li> <li> <p>control characters (<code>U+0000-001F</code>, <code>U+007F-009F</code>, <code>U+FFFE-FFFF</code>)</p> </li> <li> <p>surrogates (<code>U+D800-DFFF</code>)</p> </li> <li> <p>invalid characters (<code> U+10FFFF</code>)</p> </li> </ul> <p>To enable logging with CloudWatch Logs, the name should only contain 0-9, A-Z, a-z, - and _.</p>
        definition: <p>The Amazon States Language definition of the state machine. See <a href="https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html">Amazon States Language</a>.</p>
        role_arn: <p>The Amazon Resource Name (ARN) of the IAM role to use for this state machine.</p>
        type: <p>Determines whether a Standard or Express state machine is created. The default is <code>STANDARD</code>. You cannot update the <code>type</code> of a state machine once it has been created.</p>
        logging_configuration: <p>Defines what execution history events are logged and where they are logged.</p> <note> <p>By default, the <code>level</code> is set to <code>OFF</code>. For more information see <a href="https://docs.aws.amazon.com/step-functions/latest/dg/cloudwatch-log-level.html">Log Levels</a> in the Step Functions User Guide.</p> </note>
        tags: <p>Tags to be added when creating a state machine.</p> <p>An array of key-value pairs. For more information, see <a href="https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/cost-alloc-tags.html">Using Cost Allocation Tags</a> in the <i>Amazon Web Services Billing and Cost Management User Guide</i>, and <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_iam-tags.html">Controlling Access Using IAM Tags</a>.</p> <p>Tags may only contain Unicode letters, digits, white space, or these symbols: <code>_ . : / = + - @</code>.</p>
        tracing_configuration: <p>Selects whether X-Ray tracing is enabled.</p>
        publish: <p>Set to <code>true</code> to publish the first version of the state machine during creation. The default is <code>false</code>.</p>
        version_description: <p>Sets description about the state machine version. You can only set the description if the <code>publish</code> parameter is set to <code>true</code>. Otherwise, if you set <code>versionDescription</code>, but <code>publish</code> to <code>false</code>, this API action throws <code>ValidationException</code>.</p>
        encryption_configuration: <p>Settings to configure server-side encryption.</p>

    Raises:
        capo_sfn.errors.conflict_exception.ConflictException: <p>Updating or deleting a resource can cause an inconsistent state. This error occurs when there're concurrent requests for <a>DeleteStateMachineVersion</a>, <a>PublishStateMachineVersion</a>, or <a>UpdateStateMachine</a> with the <code>publish</code> parameter set to <code>true</code>.</p> <p>HTTP Status Code: 409</p>
        capo_sfn.errors.invalid_arn.InvalidArn: <p>The provided Amazon Resource Name (ARN) is not valid.</p>
        capo_sfn.errors.invalid_definition.InvalidDefinition: <p>The provided Amazon States Language definition is not valid.</p>
        capo_sfn.errors.invalid_encryption_configuration.InvalidEncryptionConfiguration: <p>Received when <code>encryptionConfiguration</code> is specified but various conditions exist which make the configuration invalid. For example, if <code>type</code> is set to <code>CUSTOMER_MANAGED_KMS_KEY</code>, but <code>kmsKeyId</code> is null, or <code>kmsDataKeyReusePeriodSeconds</code> is not between 60 and 900, or the KMS key is not symmetric or inactive.</p>
        capo_sfn.errors.invalid_logging_configuration.InvalidLoggingConfiguration: <p>Configuration is not valid.</p>
        capo_sfn.errors.invalid_name.InvalidName: <p>The provided name is not valid.</p>
        capo_sfn.errors.invalid_tracing_configuration.InvalidTracingConfiguration: <p>Your <code>tracingConfiguration</code> key does not match, or <code>enabled</code> has not been set to <code>true</code> or <code>false</code>.</p>
        capo_sfn.errors.kms_access_denied_exception.KmsAccessDeniedException: <p>Either your KMS key policy or API caller does not have the required permissions.</p>
        capo_sfn.errors.kms_throttling_exception.KmsThrottlingException: <p>Received when KMS returns <code>ThrottlingException</code> for a KMS call that Step Functions makes on behalf of the caller.</p>
        capo_sfn.errors.state_machine_already_exists.StateMachineAlreadyExists: <p>A state machine with the same name but a different definition or role ARN already exists.</p>
        capo_sfn.errors.state_machine_deleting.StateMachineDeleting: <p>The specified state machine is being deleted.</p>
        capo_sfn.errors.state_machine_limit_exceeded.StateMachineLimitExceeded: <p>The maximum number of state machines has been reached. Existing state machines must be deleted before a new state machine can be created.</p>
        capo_sfn.errors.state_machine_type_not_supported.StateMachineTypeNotSupported: <p>State machine type is not supported.</p>
        capo_sfn.errors.too_many_tags.TooManyTags: <p>You've exceeded the number of tags allowed for a resource. See the <a href="https://docs.aws.amazon.com/step-functions/latest/dg/limits.html"> Limits Topic</a> in the Step Functions Developer Guide.</p>
        capo_sfn.errors.validation_exception.ValidationException: <p>The input does not satisfy the constraints specified by an Amazon Web Services service.</p>
        capo_sfn.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_sfn.types.create_state_machine_input.CreateStateMachineInput]",
    ) -> OperationResponse[
        "capo_sfn.types.create_state_machine_output.CreateStateMachineOutput"
    ]:
        import capo_sfn._operations.aws_step_functions.create_state_machine

        output, http_response = (
            capo_sfn._operations.aws_step_functions.create_state_machine.create_state_machine(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_sfn.types.create_state_machine_input.CreateStateMachineInput",
    ) -> dict[str, Any]:
        import capo_sfn.types.create_state_machine_input

        return capo_sfn.types.create_state_machine_input.redact_sensitive(input_)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateStateMachine", redact_input=_redact_input),
    )
    input_: capo_sfn.types.create_state_machine_input.CreateStateMachineInput = {
        "name": name,
        "definition": definition,
        "role_arn": role_arn,
    }
    if type is not None:
        input_["type"] = type
    if logging_configuration is not None:
        input_["logging_configuration"] = logging_configuration
    if tags is not None:
        input_["tags"] = tags
    if tracing_configuration is not None:
        input_["tracing_configuration"] = tracing_configuration
    if publish is not None:
        input_["publish"] = publish
    if version_description is not None:
        input_["version_description"] = version_description
    if encryption_configuration is not None:
        input_["encryption_configuration"] = encryption_configuration

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output