Skip to content

create_experiment_definition async

create_experiment_definition(
    application_identifier: Identifier,
    name: NameWithReservedAwsPrefix,
    configuration_profile_identifier: Identifier,
    environment_identifier: Identifier,
    flag_key: FlagKey,
    treatments: TreatmentInputList,
    control: TreatmentInput,
    audience_rule: Rule,
    *,
    config_overrides: Optional[AsyncAppConfigClientConfig] = None,
    hypothesis: Optional[Description] = None,
    audience_description: Optional[Description] = None,
    launch_criteria: Optional[Description] = None,
    tags: Optional[TagMap] = None,
) -> ExperimentDefinition

Creates an experiment definition in AppConfig. An experiment definition describes the purpose, scope, and operational configuration of an experiment, including the target audience, feature flag, and treatment configurations.

Parameters:

  • application_identifier (Identifier) –

    The application ID or name.

  • name (NameWithReservedAwsPrefix) –

    A name for the experiment definition.

  • configuration_profile_identifier (Identifier) –

    The configuration profile ID or name that stores the feature flag.

  • environment_identifier (Identifier) –

    The environment ID or name where the experiment will run.

  • flag_key (FlagKey) –

    The key of the existing feature flag to use with the experiment.

  • treatments (TreatmentInputList) –

    A list of treatments to evaluate during the experiment. Each treatment defines a distinct variation compared to the control.

  • control (TreatmentInput) –

    The control treatment that represents the baseline experience for comparison.

  • audience_rule (Rule) –

    A rule that defines which users are eligible to be assigned to treatments during the experiment.

  • hypothesis (Optional[Description], default: None ) –

    A description of the goal or hypothesis the experiment is designed to validate.

  • audience_description (Optional[Description], default: None ) –

    A description of the intended audience for the experiment.

  • launch_criteria (Optional[Description], default: None ) –

    Information about the conditions under which you would launch the winning treatment.

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

    The tags to assign to the experiment definition. Tags help organize and categorize your AppConfig resources.

Raises:

  • BadRequestException –

    The input fails to satisfy the constraints specified by an Amazon Web Services service.

  • ConflictException –

    The request could not be processed because of conflict in the current state of the resource.

  • InternalServerException –

    There was an internal failure in the AppConfig service.

  • ResourceNotFoundException –

    The requested resource could not be found.

  • ServiceQuotaExceededException –

    The number of one more AppConfig resources exceeds the maximum allowed. Verify that your environment doesn't exceed the following service quotas:

    Applications: 100 max

    To resolve this issue, you can delete one or more resources and try again. Or, you can request a quota increase. For more information about quotas and to request an increase, see Service quotas for AppConfig in the Amazon Web Services General Reference.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

To create an experiment definition The following CreateExperimentDefinition example creates an experiment definition that tests a feature flag with a 50/50 traffic split.

>>> await client.create_experiment_definition(application_identifier='339ohji', configuration_profile_identifier='ur8hx2f', environment_identifier='54j1r29', name='Example-Experiment-Definition', flag_key='my-feature-flag', treatments=[{'Weight': 50, 'FlagValue': {'Enabled': True}}], control={'Weight': 50, 'FlagValue': {'Enabled': False}}, audience_rule='(eq $country "US")')
Source code in docs_src/capo_appconfig/_services/async_app_config.py
async def create_experiment_definition(
    self,
    application_identifier: "capo_appconfig.types.identifier.Identifier",
    name: "capo_appconfig.types.name_with_reserved_aws_prefix.NameWithReservedAwsPrefix",
    configuration_profile_identifier: "capo_appconfig.types.identifier.Identifier",
    environment_identifier: "capo_appconfig.types.identifier.Identifier",
    flag_key: "capo_appconfig.types.flag_key.FlagKey",
    treatments: "capo_appconfig.types.treatment_input_list.TreatmentInputList",
    control: "capo_appconfig.types.treatment_input.TreatmentInput",
    audience_rule: "capo_appconfig.types.rule.Rule",
    *,
    config_overrides: Optional[AsyncAppConfigClientConfig] = None,
    hypothesis: Optional["capo_appconfig.types.description.Description"] = None,
    audience_description: Optional[
        "capo_appconfig.types.description.Description"
    ] = None,
    launch_criteria: Optional[
        "capo_appconfig.types.description.Description"
    ] = None,
    tags: Optional["capo_appconfig.types.tag_map.TagMap"] = None,
) -> "capo_appconfig.types.experiment_definition.ExperimentDefinition":
    """<p>Creates an experiment definition in AppConfig. An experiment definition describes the purpose, scope, and operational configuration of an experiment, including the target audience, feature flag, and treatment configurations.</p>

    Args:
        application_identifier: <p>The application ID or name.</p>
        name: <p>A name for the experiment definition.</p>
        configuration_profile_identifier: <p>The configuration profile ID or name that stores the feature flag.</p>
        environment_identifier: <p>The environment ID or name where the experiment will run.</p>
        flag_key: <p>The key of the existing feature flag to use with the experiment.</p>
        treatments: <p>A list of treatments to evaluate during the experiment. Each treatment defines a distinct variation compared to the control.</p>
        control: <p>The control treatment that represents the baseline experience for comparison.</p>
        audience_rule: <p>A rule that defines which users are eligible to be assigned to treatments during the experiment.</p>
        hypothesis: <p>A description of the goal or hypothesis the experiment is designed to validate.</p>
        audience_description: <p>A description of the intended audience for the experiment.</p>
        launch_criteria: <p>Information about the conditions under which you would launch the winning treatment.</p>
        tags: <p>The tags to assign to the experiment definition. Tags help organize and categorize your AppConfig resources.</p>

    Raises:
        capo_appconfig.errors.bad_request_exception.BadRequestException: <p>The input fails to satisfy the constraints specified by an Amazon Web Services service.</p>
        capo_appconfig.errors.conflict_exception.ConflictException: <p>The request could not be processed because of conflict in the current state of the resource.</p>
        capo_appconfig.errors.internal_server_exception.InternalServerException: <p>There was an internal failure in the AppConfig service.</p>
        capo_appconfig.errors.resource_not_found_exception.ResourceNotFoundException: <p>The requested resource could not be found.</p>
        capo_appconfig.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The number of one more AppConfig resources exceeds the maximum allowed. Verify that your environment doesn't exceed the following service quotas:</p> <p>Applications: 100 max</p> <p>To resolve this issue, you can delete one or more resources and try again. Or, you can request a quota increase. For more information about quotas and to request an increase, see <a href="https://docs.aws.amazon.com/general/latest/gr/appconfig.html#limits_appconfig">Service quotas for AppConfig</a> in the Amazon Web Services General Reference.</p>
        capo_appconfig.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To create an experiment definition
        The following CreateExperimentDefinition example creates an experiment definition that tests a feature flag with a 50/50 traffic split.

        >>> await client.create_experiment_definition(application_identifier='339ohji', configuration_profile_identifier='ur8hx2f', environment_identifier='54j1r29', name='Example-Experiment-Definition', flag_key='my-feature-flag', treatments=[{'Weight': 50, 'FlagValue': {'Enabled': True}}], control={'Weight': 50, 'FlagValue': {'Enabled': False}}, audience_rule='(eq $country "US")')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_appconfig.types.create_experiment_definition_request.CreateExperimentDefinitionRequest]",
    ) -> AsyncOperationResponse[
        "capo_appconfig.types.experiment_definition.ExperimentDefinition"
    ]:
        import capo_appconfig._operations.amazon_app_config.create_experiment_definition

        (
            output,
            http_response,
        ) = await capo_appconfig._operations.amazon_app_config.create_experiment_definition.async_create_experiment_definition(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateExperimentDefinition")
    )
    input_: capo_appconfig.types.create_experiment_definition_request.CreateExperimentDefinitionRequest = {
        "application_identifier": application_identifier,
        "name": name,
        "configuration_profile_identifier": configuration_profile_identifier,
        "environment_identifier": environment_identifier,
        "flag_key": flag_key,
        "treatments": treatments,
        "control": control,
        "audience_rule": audience_rule,
    }
    if hypothesis is not None:
        input_["hypothesis"] = hypothesis
    if audience_description is not None:
        input_["audience_description"] = audience_description
    if launch_criteria is not None:
        input_["launch_criteria"] = launch_criteria
    if tags is not None:
        input_["tags"] = tags

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output