Skip to content

create_fleet async

create_fleet(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    dry_run: Optional[Boolean] = None,
    client_token: Optional[String] = None,
    spot_options: Optional[SpotOptionsRequest] = None,
    on_demand_options: Optional[OnDemandOptionsRequest] = None,
    reserved_capacity_options: Optional[ReservedCapacityOptionsRequest] = None,
    excess_capacity_termination_policy: Optional[
        FleetExcessCapacityTerminationPolicy
    ] = None,
    launch_template_configs: Optional[FleetLaunchTemplateConfigListRequest] = None,
    target_capacity_specification: Optional[TargetCapacitySpecificationRequest] = None,
    terminate_instances_with_expiration: Optional[Boolean] = None,
    type: Optional[FleetType] = None,
    valid_from: Optional[DateTime] = None,
    valid_until: Optional[DateTime] = None,
    replace_unhealthy_instances: Optional[Boolean] = None,
    tag_specifications: Optional[TagSpecificationList] = None,
    context: Optional[String] = None,
) -> CreateFleetResult

Creates an EC2 Fleet that contains the configuration information for On-Demand Instances and Spot Instances. Instances are launched immediately if there is available capacity.

A single EC2 Fleet can include multiple launch specifications that vary by instance type, AMI, Availability Zone, or subnet.

For more information, see EC2 Fleet in the Amazon EC2 User Guide.

Parameters:

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • client_token (Optional[String], default: None ) –

    Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. If you do not specify a client token, a randomly generated token is used for the request to ensure idempotency.

    For more information, see Ensuring idempotency.

  • spot_options (Optional[SpotOptionsRequest], default: None ) –

    Describes the configuration of Spot Instances in an EC2 Fleet.

  • on_demand_options (Optional[OnDemandOptionsRequest], default: None ) –

    Describes the configuration of On-Demand Instances in an EC2 Fleet.

  • reserved_capacity_options (Optional[ReservedCapacityOptionsRequest], default: None ) –

    Defines EC2 Fleet preferences for utilizing reserved capacity when DefaultTargetCapacityType is set to reserved-capacity.

    Supported only for fleets of type instant.

  • excess_capacity_termination_policy (Optional[FleetExcessCapacityTerminationPolicy], default: None ) –

    Indicates whether running instances should be terminated if the total target capacity of the EC2 Fleet is decreased below the current size of the EC2 Fleet.

    Supported only for fleets of type maintain.

  • launch_template_configs (Optional[FleetLaunchTemplateConfigListRequest], default: None ) –

    The configuration for the EC2 Fleet.

  • target_capacity_specification (Optional[TargetCapacitySpecificationRequest], default: None ) –

    The number of units to request.

  • terminate_instances_with_expiration (Optional[Boolean], default: None ) –

    Indicates whether running instances should be terminated when the EC2 Fleet expires.

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

    The fleet type. The default value is maintain.

    • maintain - The EC2 Fleet places an asynchronous request for your desired capacity, and continues to maintain your desired Spot capacity by replenishing interrupted Spot Instances.

    • request - The EC2 Fleet places an asynchronous one-time request for your desired capacity, but does submit Spot requests in alternative capacity pools if Spot capacity is unavailable, and does not maintain Spot capacity if Spot Instances are interrupted.

    • instant - The EC2 Fleet places a synchronous one-time request for your desired capacity, and returns errors for any instances that could not be launched.

    For more information, see EC2 Fleet request types in the Amazon EC2 User Guide.

  • valid_from (Optional[DateTime], default: None ) –

    The start date and time of the request, in UTC format (for example, YYYY-MM-DDTHH:MM:SSZ). The default is to start fulfilling the request immediately.

  • valid_until (Optional[DateTime], default: None ) –

    The end date and time of the request, in UTC format (for example, YYYY-MM-DDTHH:MM:SSZ). At this point, no new EC2 Fleet requests are placed or able to fulfill the request. If no value is specified, the request remains until you cancel it.

  • replace_unhealthy_instances (Optional[Boolean], default: None ) –

    Indicates whether EC2 Fleet should replace unhealthy Spot Instances. Supported only for fleets of type maintain. For more information, see EC2 Fleet health checks in the Amazon EC2 User Guide.

  • tag_specifications (Optional[TagSpecificationList], default: None ) –

    The key-value pair for tagging the EC2 Fleet request on creation. For more information, see Tag your resources.

    If the fleet type is instant, specify a resource type of fleet to tag the fleet, instance to tag the instances at launch, volume to tag the volumes at launch, or network-interface to tag the network interfaces at launch.

    If the fleet type is maintain or request, specify a resource type of fleet to tag the fleet. You cannot specify a resource type of instance, volume, or network-interface. To tag instances at launch, specify the tags in a launch template.

  • context (Optional[String], default: None ) –

    Reserved.

Raises:

Source code in docs_src/capo_ec2/_services/async_ec2.py
async def create_fleet(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    client_token: Optional["capo_ec2.types.string.String"] = None,
    spot_options: Optional[
        "capo_ec2.types.spot_options_request.SpotOptionsRequest"
    ] = None,
    on_demand_options: Optional[
        "capo_ec2.types.on_demand_options_request.OnDemandOptionsRequest"
    ] = None,
    reserved_capacity_options: Optional[
        "capo_ec2.types.reserved_capacity_options_request.ReservedCapacityOptionsRequest"
    ] = None,
    excess_capacity_termination_policy: Optional[
        "capo_ec2.types.fleet_excess_capacity_termination_policy.FleetExcessCapacityTerminationPolicy"
    ] = None,
    launch_template_configs: Optional[
        "capo_ec2.types.fleet_launch_template_config_list_request.FleetLaunchTemplateConfigListRequest"
    ] = None,
    target_capacity_specification: Optional[
        "capo_ec2.types.target_capacity_specification_request.TargetCapacitySpecificationRequest"
    ] = None,
    terminate_instances_with_expiration: Optional[
        "capo_ec2.types.boolean.Boolean"
    ] = None,
    type: Optional["capo_ec2.types.fleet_type.FleetType"] = None,
    valid_from: Optional["capo_ec2.types.date_time.DateTime"] = None,
    valid_until: Optional["capo_ec2.types.date_time.DateTime"] = None,
    replace_unhealthy_instances: Optional["capo_ec2.types.boolean.Boolean"] = None,
    tag_specifications: Optional[
        "capo_ec2.types.tag_specification_list.TagSpecificationList"
    ] = None,
    context: Optional["capo_ec2.types.string.String"] = None,
) -> "capo_ec2.types.create_fleet_result.CreateFleetResult":
    """<p>Creates an EC2 Fleet that contains the configuration information for On-Demand Instances and Spot Instances. Instances are launched immediately if there is available capacity.</p> <p>A single EC2 Fleet can include multiple launch specifications that vary by instance type, AMI, Availability Zone, or subnet.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet.html">EC2 Fleet</a> in the <i>Amazon EC2 User Guide</i>.</p>

    Args:
        dry_run: <p>Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>
        client_token: <p>Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. If you do not specify a client token, a randomly generated token is used for the request to ensure idempotency.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html">Ensuring idempotency</a>.</p>
        spot_options: <p>Describes the configuration of Spot Instances in an EC2 Fleet.</p>
        on_demand_options: <p>Describes the configuration of On-Demand Instances in an EC2 Fleet.</p>
        reserved_capacity_options: <p>Defines EC2 Fleet preferences for utilizing reserved capacity when DefaultTargetCapacityType is set to <code>reserved-capacity</code>.</p> <p>Supported only for fleets of type <code>instant</code>.</p>
        excess_capacity_termination_policy: <p>Indicates whether running instances should be terminated if the total target capacity of the EC2 Fleet is decreased below the current size of the EC2 Fleet.</p> <p>Supported only for fleets of type <code>maintain</code>.</p>
        launch_template_configs: <p>The configuration for the EC2 Fleet.</p>
        target_capacity_specification: <p>The number of units to request.</p>
        terminate_instances_with_expiration: <p>Indicates whether running instances should be terminated when the EC2 Fleet expires.</p>
        type: <p>The fleet type. The default value is <code>maintain</code>.</p> <ul> <li> <p> <code>maintain</code> - The EC2 Fleet places an asynchronous request for your desired capacity, and continues to maintain your desired Spot capacity by replenishing interrupted Spot Instances.</p> </li> <li> <p> <code>request</code> - The EC2 Fleet places an asynchronous one-time request for your desired capacity, but does submit Spot requests in alternative capacity pools if Spot capacity is unavailable, and does not maintain Spot capacity if Spot Instances are interrupted.</p> </li> <li> <p> <code>instant</code> - The EC2 Fleet places a synchronous one-time request for your desired capacity, and returns errors for any instances that could not be launched.</p> </li> </ul> <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-request-type.html">EC2 Fleet request types</a> in the <i>Amazon EC2 User Guide</i>.</p>
        valid_from: <p>The start date and time of the request, in UTC format (for example, <i>YYYY</i>-<i>MM</i>-<i>DD</i>T<i>HH</i>:<i>MM</i>:<i>SS</i>Z). The default is to start fulfilling the request immediately.</p>
        valid_until: <p>The end date and time of the request, in UTC format (for example, <i>YYYY</i>-<i>MM</i>-<i>DD</i>T<i>HH</i>:<i>MM</i>:<i>SS</i>Z). At this point, no new EC2 Fleet requests are placed or able to fulfill the request. If no value is specified, the request remains until you cancel it.</p>
        replace_unhealthy_instances: <p>Indicates whether EC2 Fleet should replace unhealthy Spot Instances. Supported only for fleets of type <code>maintain</code>. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/manage-ec2-fleet.html#ec2-fleet-health-checks">EC2 Fleet health checks</a> in the <i>Amazon EC2 User Guide</i>.</p>
        tag_specifications: <p>The key-value pair for tagging the EC2 Fleet request on creation. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#tag-resources">Tag your resources</a>.</p> <p>If the fleet type is <code>instant</code>, specify a resource type of <code>fleet</code> to tag the fleet, <code>instance</code> to tag the instances at launch, <code>volume</code> to tag the volumes at launch, or <code>network-interface</code> to tag the network interfaces at launch.</p> <p>If the fleet type is <code>maintain</code> or <code>request</code>, specify a resource type of <code>fleet</code> to tag the fleet. You cannot specify a resource type of <code>instance</code>, <code>volume</code>, or <code>network-interface</code>. To tag instances at launch, specify the tags in a <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html#create-launch-template">launch template</a>.</p>
        context: <p>Reserved.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.create_fleet_request.CreateFleetRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.create_fleet_result.CreateFleetResult"
    ]:
        import capo_ec2._operations.amazon_ec2.create_fleet

        (
            output,
            http_response,
        ) = await capo_ec2._operations.amazon_ec2.create_fleet.async_create_fleet(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_ec2.types.create_fleet_request.CreateFleetRequest",
    ) -> dict[str, Any]:
        import capo_ec2.types.create_fleet_request

        return capo_ec2.types.create_fleet_request.redact_sensitive(input_)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateFleet", redact_input=_redact_input),
    )
    input_: capo_ec2.types.create_fleet_request.CreateFleetRequest = {}
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if spot_options is not None:
        input_["spot_options"] = spot_options
    if on_demand_options is not None:
        input_["on_demand_options"] = on_demand_options
    if reserved_capacity_options is not None:
        input_["reserved_capacity_options"] = reserved_capacity_options
    if excess_capacity_termination_policy is not None:
        input_["excess_capacity_termination_policy"] = (
            excess_capacity_termination_policy
        )
    if launch_template_configs is not None:
        input_["launch_template_configs"] = launch_template_configs
    if target_capacity_specification is not None:
        input_["target_capacity_specification"] = target_capacity_specification
    if terminate_instances_with_expiration is not None:
        input_["terminate_instances_with_expiration"] = (
            terminate_instances_with_expiration
        )
    if type is not None:
        input_["type"] = type
    if valid_from is not None:
        input_["valid_from"] = valid_from
    if valid_until is not None:
        input_["valid_until"] = valid_until
    if replace_unhealthy_instances is not None:
        input_["replace_unhealthy_instances"] = replace_unhealthy_instances
    if tag_specifications is not None:
        input_["tag_specifications"] = tag_specifications
    if context is not None:
        input_["context"] = context

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