PutClusterCapacityProvidersCommand

Modifies the available capacity providers and the default capacity provider strategy for a cluster.

You must specify both the available capacity providers and a default capacity provider strategy for the cluster. If the specified cluster has existing capacity providers associated with it, you must specify all existing capacity providers in addition to any new ones you want to add. Any existing capacity providers that are associated with a cluster that are omitted from a PutClusterCapacityProviders  API call will be disassociated with the cluster. You can only disassociate an existing capacity provider from a cluster if it's not being used by any existing tasks.

When creating a service or running a task on a cluster, if no capacity provider or launch type is specified, then the cluster's default capacity provider strategy is used. We recommend that you define a default capacity provider strategy for your cluster. However, you must specify an empty array ([]) to bypass defining a default strategy.

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { ECSClient, PutClusterCapacityProvidersCommand } from "@aws-sdk/client-ecs"; // ES Modules import
// const { ECSClient, PutClusterCapacityProvidersCommand } = require("@aws-sdk/client-ecs"); // CommonJS import
const client = new ECSClient(config);
const input = { // PutClusterCapacityProvidersRequest
  cluster: "STRING_VALUE", // required
  capacityProviders: [ // StringList // required
    "STRING_VALUE",
  ],
  defaultCapacityProviderStrategy: [ // CapacityProviderStrategy // required
    { // CapacityProviderStrategyItem
      capacityProvider: "STRING_VALUE", // required
      weight: Number("int"),
      base: Number("int"),
    },
  ],
};
const command = new PutClusterCapacityProvidersCommand(input);
const response = await client.send(command);
// { // PutClusterCapacityProvidersResponse
//   cluster: { // Cluster
//     clusterArn: "STRING_VALUE",
//     clusterName: "STRING_VALUE",
//     configuration: { // ClusterConfiguration
//       executeCommandConfiguration: { // ExecuteCommandConfiguration
//         kmsKeyId: "STRING_VALUE",
//         logging: "NONE" || "DEFAULT" || "OVERRIDE",
//         logConfiguration: { // ExecuteCommandLogConfiguration
//           cloudWatchLogGroupName: "STRING_VALUE",
//           cloudWatchEncryptionEnabled: true || false,
//           s3BucketName: "STRING_VALUE",
//           s3EncryptionEnabled: true || false,
//           s3KeyPrefix: "STRING_VALUE",
//         },
//       },
//       managedStorageConfiguration: { // ManagedStorageConfiguration
//         kmsKeyId: "STRING_VALUE",
//         fargateEphemeralStorageKmsKeyId: "STRING_VALUE",
//       },
//     },
//     status: "STRING_VALUE",
//     registeredContainerInstancesCount: Number("int"),
//     runningTasksCount: Number("int"),
//     pendingTasksCount: Number("int"),
//     activeServicesCount: Number("int"),
//     statistics: [ // Statistics
//       { // KeyValuePair
//         name: "STRING_VALUE",
//         value: "STRING_VALUE",
//       },
//     ],
//     tags: [ // Tags
//       { // Tag
//         key: "STRING_VALUE",
//         value: "STRING_VALUE",
//       },
//     ],
//     settings: [ // ClusterSettings
//       { // ClusterSetting
//         name: "containerInsights",
//         value: "STRING_VALUE",
//       },
//     ],
//     capacityProviders: [ // StringList
//       "STRING_VALUE",
//     ],
//     defaultCapacityProviderStrategy: [ // CapacityProviderStrategy
//       { // CapacityProviderStrategyItem
//         capacityProvider: "STRING_VALUE", // required
//         weight: Number("int"),
//         base: Number("int"),
//       },
//     ],
//     attachments: [ // Attachments
//       { // Attachment
//         id: "STRING_VALUE",
//         type: "STRING_VALUE",
//         status: "STRING_VALUE",
//         details: [ // AttachmentDetails
//           {
//             name: "STRING_VALUE",
//             value: "STRING_VALUE",
//           },
//         ],
//       },
//     ],
//     attachmentsStatus: "STRING_VALUE",
//     serviceConnectDefaults: { // ClusterServiceConnectDefaults
//       namespace: "STRING_VALUE",
//     },
//   },
// };

Example Usage

// This example adds an existing capacity provider "MyCapacityProvider2" to a cluster that already has the
    capacity provider "MyCapacityProvider1" associated with it. Both "MyCapacityProvider2" and
    "MyCapacityProvider1" need to be specified.
const input = {
"capacityProviders": [
"MyCapacityProvider1",
"MyCapacityProvider2"
],
"cluster": "MyCluster",
"defaultCapacityProviderStrategy": [
{
"capacityProvider": "MyCapacityProvider1",
"weight": 1
},
{
"capacityProvider": "MyCapacityProvider2",
"weight": 1
}
]
};
const command = new PutClusterCapacityProvidersCommand(input);
const response = await client.send(command);
/* response ==
{
"cluster": {
"activeServicesCount": 0,
"attachments": [
{
"type": "as_policy",
"details": [
{
"name": "capacityProviderName",
"value": "MyCapacityProvider1"
},
{
"name": "scalingPolicyName",
"value": "ECSManagedAutoScalingPolicy-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"
}
],
"id": "0fb0c8f4-6edd-4de1-9b09-17e470ee1918",
"status": "ACTIVE"
},
{
"type": "as_policy",
"details": [
{
"name": "capacityProviderName",
"value": "MyCapacityProvider2"
},
{
"name": "scalingPolicyName",
"value": "ECSManagedAutoScalingPolicy-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222"
}
],
"id": "ae592060-2382-4663-9476-b015c685593c",
"status": "ACTIVE"
}
],
"attachmentsStatus": "UPDATE_IN_PROGRESS",
"capacityProviders": [
"MyCapacityProvider1",
"MyCapacityProvider2"
],
"clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster",
"clusterName": "MyCluster",
"defaultCapacityProviderStrategy": [
{
"base": 0,
"capacityProvider": "MyCapacityProvider1",
"weight": 1
},
{
"base": 0,
"capacityProvider": "MyCapacityProvider2",
"weight": 1
}
],
"pendingTasksCount": 0,
"registeredContainerInstancesCount": 0,
"runningTasksCount": 0,
"settings": [
{
"name": "containerInsights",
"value": "enabled"
}
],
"statistics": [],
"status": "ACTIVE",
"tags": []
}
}
*\/
// example id: to-add-an-existing-capacity-provider-to-a-cluster-1734385195698
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
JavaScriptLn 1, Col 1
Errors: 0 Warnings: 0

PutClusterCapacityProvidersCommand Input

Parameter
Type
Description
capacityProviders
Required
string[] | undefined

The name of one or more capacity providers to associate with the cluster.

If specifying a capacity provider that uses an Auto Scaling group, the capacity provider must already be created. New capacity providers can be created with the CreateCapacityProvider  API operation.

To use a Fargate capacity provider, specify either the FARGATE or FARGATE_SPOT capacity providers. The Fargate capacity providers are available to all accounts and only need to be associated with a cluster to be used.

cluster
Required
string | undefined

The short name or full Amazon Resource Name (ARN) of the cluster to modify the capacity provider settings for. If you don't specify a cluster, the default cluster is assumed.

defaultCapacityProviderStrategy
Required
CapacityProviderStrategyItem[] | undefined

The capacity provider strategy to use by default for the cluster.

When creating a service or running a task on a cluster, if no capacity provider or launch type is specified then the default capacity provider strategy for the cluster is used.

A capacity provider strategy consists of one or more capacity providers along with the base and weight to assign to them. A capacity provider must be associated with the cluster to be used in a capacity provider strategy. The PutClusterCapacityProviders  API is used to associate a capacity provider with a cluster. Only capacity providers with an ACTIVE or UPDATING status can be used.

If specifying a capacity provider that uses an Auto Scaling group, the capacity provider must already be created. New capacity providers can be created with the CreateCapacityProvider  API operation.

To use a Fargate capacity provider, specify either the FARGATE or FARGATE_SPOT capacity providers. The Fargate capacity providers are available to all accounts and only need to be associated with a cluster to be used.

PutClusterCapacityProvidersCommand Output

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
cluster
Cluster | undefined

Details about the cluster.

Throws

Name
Fault
Details
ClientException
client

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.

The following list includes additional causes for the error:

  • The RunTask could not be processed because you use managed scaling and there is a capacity error because the quota of tasks in the PROVISIONING per cluster has been reached. For information about the service quotas, see Amazon ECS service quotas .

ClusterNotFoundException
client

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

InvalidParameterException
client

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

ResourceInUseException
client

The specified resource is in-use and can't be removed.

ServerException
server

These errors are usually caused by a server issue.

UpdateInProgressException
client

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.

ECSServiceException
Base exception class for all service exceptions from ECS service.