Skip to content

create_capacity_provider

create_capacity_provider(
    name: String,
    *,
    config_overrides: Optional[ECSClientConfig] = None,
    cluster: Optional[String] = None,
    auto_scaling_group_provider: Optional[AutoScalingGroupProvider] = None,
    managed_instances_provider: Optional[
        CreateManagedInstancesProviderConfiguration
    ] = None,
    tags: Optional[Tags] = None,
) -> CreateCapacityProviderResponse

Creates a capacity provider. Capacity providers are associated with a cluster and are used in capacity provider strategies to facilitate cluster auto scaling. You can create capacity providers for Amazon ECS Managed Instances and EC2 instances. Fargate has the predefined FARGATE and FARGATE_SPOT capacity providers.

Parameters:

  • name (String) –

    The name of the capacity provider. Up to 255 characters are allowed. They include letters (both upper and lowercase letters), numbers, underscores (_), and hyphens (-). The name can't be prefixed with "aws", "ecs", or "fargate".

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

    The name of the cluster to associate with the capacity provider. When you create a capacity provider with Amazon ECS Managed Instances, it becomes available only within the specified cluster.

  • auto_scaling_group_provider (Optional[AutoScalingGroupProvider], default: None ) –

    The details of the Auto Scaling group for the capacity provider.

  • managed_instances_provider (Optional[CreateManagedInstancesProviderConfiguration], default: None ) –

    The configuration for the Amazon ECS Managed Instances provider. This configuration specifies how Amazon ECS manages Amazon EC2 instances on your behalf, including the infrastructure role, instance launch template, and tag propagation settings.

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

    The metadata that you apply to the capacity provider to categorize and organize them more conveniently. Each tag consists of a key and an optional value. You define both of them.

    The following basic restrictions apply to tags:

    • Maximum number of tags per resource - 50

    • For each resource, each tag key must be unique, and each tag key can have only one value.

    • Maximum key length - 128 Unicode characters in UTF-8

    • Maximum value length - 256 Unicode characters in UTF-8

    • If your tagging schema is used across multiple services and resources, remember that other services may have restrictions on allowed characters. Generally allowed characters are: letters, numbers, and spaces representable in UTF-8, and the following characters: + - = . _ : / @.

    • Tag keys and values are case-sensitive.

    • Do not use aws:, AWS:, or any upper or lowercase combination of such as a prefix for either keys or values as it is reserved for Amazon Web Services use. You cannot edit or delete tag keys or values with this prefix. Tags with this prefix do not count against your tags per resource limit.

Raises:

  • AccessDeniedException –

    You don't have authorization to perform the requested action.

  • ClientException –

    These errors are usually caused by a client action. This client action might be using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Or, it might be specifying an identifier that isn't valid.

  • ClusterNotFoundException –

    The specified cluster wasn't found. You can view your available clusters with ListClusters. Amazon ECS clusters are Region specific.

  • InvalidParameterException –

    The specified parameter isn't valid. Review the available parameters for the API request.

    For more information about service event errors, see Amazon ECS service event messages.

  • LimitExceededException –

    The limit for the resource was exceeded.

  • ServerException –

    These errors are usually caused by a server issue.

  • UnsupportedFeatureException –

    The specified task isn't supported in this Region.

  • UpdateInProgressException –

    There's already a current Amazon ECS container agent update in progress on the container instance that's specified. If the container agent becomes disconnected while it's in a transitional stage, such as PENDING or STAGING, the update process can get stuck in that state. However, when the agent reconnects, it resumes where it stopped previously.

  • UnknownServiceError –

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

Examples:

To create a capacity provider This example creates a capacity provider that uses the specified Auto Scaling group MyASG and has managed scaling and manager termination protection enabled.

>>> client.create_capacity_provider(name='MyCapacityProvider', auto_scaling_group_provider={'autoScalingGroupArn': 'arn:aws:autoscaling:us-east-1:123456789012:autoScalingGroup:57ffcb94-11f0-4d6d-bf60-3bac5EXAMPLE:autoScalingGroupName/MyASG', 'managedScaling': {'status': 'ENABLED', 'targetCapacity': 100}, 'managedTerminationProtection': 'ENABLED'})
Source code in docs_src/capo_ecs/_services/ecs.py
def create_capacity_provider(
    self,
    name: "capo_ecs.types.string.String",
    *,
    config_overrides: Optional[ECSClientConfig] = None,
    cluster: Optional["capo_ecs.types.string.String"] = None,
    auto_scaling_group_provider: Optional[
        "capo_ecs.types.auto_scaling_group_provider.AutoScalingGroupProvider"
    ] = None,
    managed_instances_provider: Optional[
        "capo_ecs.types.create_managed_instances_provider_configuration.CreateManagedInstancesProviderConfiguration"
    ] = None,
    tags: Optional["capo_ecs.types.tags.Tags"] = None,
) -> "capo_ecs.types.create_capacity_provider_response.CreateCapacityProviderResponse":
    """<p>Creates a capacity provider. Capacity providers are associated with a cluster and are used in capacity provider strategies to facilitate cluster auto scaling. You can create capacity providers for Amazon ECS Managed Instances and EC2 instances. Fargate has the predefined <code>FARGATE</code> and <code>FARGATE_SPOT</code> capacity providers.</p>

    Args:
        name: <p>The name of the capacity provider. Up to 255 characters are allowed. They include letters (both upper and lowercase letters), numbers, underscores (_), and hyphens (-). The name can't be prefixed with "<code>aws</code>", "<code>ecs</code>", or "<code>fargate</code>".</p>
        cluster: <p>The name of the cluster to associate with the capacity provider. When you create a capacity provider with Amazon ECS Managed Instances, it becomes available only within the specified cluster.</p>
        auto_scaling_group_provider: <p>The details of the Auto Scaling group for the capacity provider.</p>
        managed_instances_provider: <p>The configuration for the Amazon ECS Managed Instances provider. This configuration specifies how Amazon ECS manages Amazon EC2 instances on your behalf, including the infrastructure role, instance launch template, and tag propagation settings.</p>
        tags: <p>The metadata that you apply to the capacity provider to categorize and organize them more conveniently. Each tag consists of a key and an optional value. You define both of them.</p> <p>The following basic restrictions apply to tags:</p> <ul> <li> <p>Maximum number of tags per resource - 50</p> </li> <li> <p>For each resource, each tag key must be unique, and each tag key can have only one value.</p> </li> <li> <p>Maximum key length - 128 Unicode characters in UTF-8</p> </li> <li> <p>Maximum value length - 256 Unicode characters in UTF-8</p> </li> <li> <p>If your tagging schema is used across multiple services and resources, remember that other services may have restrictions on allowed characters. Generally allowed characters are: letters, numbers, and spaces representable in UTF-8, and the following characters: + - = . _ : / @.</p> </li> <li> <p>Tag keys and values are case-sensitive.</p> </li> <li> <p>Do not use <code>aws:</code>, <code>AWS:</code>, or any upper or lowercase combination of such as a prefix for either keys or values as it is reserved for Amazon Web Services use. You cannot edit or delete tag keys or values with this prefix. Tags with this prefix do not count against your tags per resource limit.</p> </li> </ul>

    Raises:
        capo_ecs.errors.access_denied_exception.AccessDeniedException: <p>You don't have authorization to perform the requested action.</p>
        capo_ecs.errors.client_exception.ClientException: <p>These errors are usually caused by a client action. This client action might be using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Or, it might be specifying an identifier that isn't valid.</p>
        capo_ecs.errors.cluster_not_found_exception.ClusterNotFoundException: <p>The specified cluster wasn't found. You can view your available clusters with <a href="https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListClusters.html">ListClusters</a>. Amazon ECS clusters are Region specific.</p>
        capo_ecs.errors.invalid_parameter_exception.InvalidParameterException: <p>The specified parameter isn't valid. Review the available parameters for the API request.</p> <p>For more information about service event errors, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-event-messages-list.html">Amazon ECS service event messages</a>. </p>
        capo_ecs.errors.limit_exceeded_exception.LimitExceededException: <p>The limit for the resource was exceeded.</p>
        capo_ecs.errors.server_exception.ServerException: <p>These errors are usually caused by a server issue.</p>
        capo_ecs.errors.unsupported_feature_exception.UnsupportedFeatureException: <p>The specified task isn't supported in this Region.</p>
        capo_ecs.errors.update_in_progress_exception.UpdateInProgressException: <p>There's already a current Amazon ECS container agent update in progress on the container instance that's specified. If the container agent becomes disconnected while it's in a transitional stage, such as <code>PENDING</code> or <code>STAGING</code>, the update process can get stuck in that state. However, when the agent reconnects, it resumes where it stopped previously.</p>
        capo_ecs.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To create a capacity provider
        This example creates a capacity provider that uses the specified Auto Scaling group MyASG and has managed scaling and manager termination protection enabled.

        >>> client.create_capacity_provider(name='MyCapacityProvider', auto_scaling_group_provider={'autoScalingGroupArn': 'arn:aws:autoscaling:us-east-1:123456789012:autoScalingGroup:57ffcb94-11f0-4d6d-bf60-3bac5EXAMPLE:autoScalingGroupName/MyASG', 'managedScaling': {'status': 'ENABLED', 'targetCapacity': 100}, 'managedTerminationProtection': 'ENABLED'})
    """

    def _handler(
        req: "OperationRequest[capo_ecs.types.create_capacity_provider_request.CreateCapacityProviderRequest]",
    ) -> OperationResponse[
        "capo_ecs.types.create_capacity_provider_response.CreateCapacityProviderResponse"
    ]:
        import capo_ecs._operations.amazon_ec2_container_service_v20141113.create_capacity_provider

        output, http_response = (
            capo_ecs._operations.amazon_ec2_container_service_v20141113.create_capacity_provider.create_capacity_provider(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateCapacityProvider")
    )
    input_: capo_ecs.types.create_capacity_provider_request.CreateCapacityProviderRequest = {
        "name": name
    }
    if cluster is not None:
        input_["cluster"] = cluster
    if auto_scaling_group_provider is not None:
        input_["auto_scaling_group_provider"] = auto_scaling_group_provider
    if managed_instances_provider is not None:
        input_["managed_instances_provider"] = managed_instances_provider
    if tags is not None:
        input_["tags"] = tags

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