You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(aws-cdk):Adding Support for DefaultCapacityProviderStrategy for L2_cluster
A capacity provider strategy determines whether ECS tasks are launched on EC2 instances or Fargate/Fargate Spot. It can be specified at the cluster, service, or task level, and consists of one or more capacity providers. You can specify an optional base and weight value for finer control of how tasks are launched. The `base` specifies a minimum number of tasks on one capacity provider, and the `weight`s of each capacity provider determine how tasks are distributed after `base` is satisfied.
You can associate a default capacity provider strategy with an Amazon ECS cluster. After you do this, a default capacity provider strategy is used when creating a service or running a standalone task in the cluster and whenever a custom capacity provider strategy or a launch type isn't specified. We recommend that you define a default capacity provider strategy for each cluster.
For more information visit https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-capacity-providers.html
When the service does not have a capacity provider strategy, the cluster's default capacity provider strategy will be used. Default Capacity Provider Strategy can be added by using the method `addDefaultCapacityProviderStrategy`. A capacity provider strategy cannot contain a mix of EC2 Autoscaling Group capacity providers and Fargate providers.
```ts
declare const capacityProvider: ecs.CapacityProvider;
const cluster = new ecs.Cluster(stack, 'EcsCluster', {
enableFargateCapacityProviders: true,
});
cluster.addAsgCapacityProvider(capacityProvider);
cluster.addDefaultCapacityProviderStrategy([
{ capacityProvider: 'FARGATE', base: 10, weight: 50 },
{ capacityProvider: 'FARGATE_SPOT', weight: 50 },
]);
```
```ts
declare const capacityProvider: ecs.CapacityProvider;
const cluster = new ecs.Cluster(stack, 'EcsCluster', {
enableFargateCapacityProviders: true,
});
cluster.addAsgCapacityProvider(capacityProvider);
cluster.addDefaultCapacityProviderStrategy([
{ capacityProvider: capacityProvider.capacityProviderName },
]);
```
Related #15230
yarn build && yarn test results
<img width="680" alt="image" src="https://user-images.githubusercontent.com/115483524/216092468-82864aea-b809-48de-9cec-f4b54ec1e541.png">
> Describe the reason for this change, what the solution is, and any
> important design decisions you made.
>
> Remember to follow the [CONTRIBUTING GUIDE] and [DESIGN GUIDELINES] for any
> code you submit.
>
> [CONTRIBUTING GUIDE]: https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md
> [DESIGN GUIDELINES]: https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy file name to clipboardExpand all lines: packages/@aws-cdk/aws-ecs/README.md
+37Lines changed: 37 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1153,6 +1153,43 @@ new ecs.Ec2Service(this, 'EC2Service', {
1153
1153
});
1154
1154
```
1155
1155
1156
+
### Cluster Default Provider Strategy
1157
+
1158
+
A capacity provider strategy determines whether ECS tasks are launched on EC2 instances or Fargate/Fargate Spot. It can be specified at the cluster, service, or task level, and consists of one or more capacity providers. You can specify an optional base and weight value for finer control of how tasks are launched. The `base` specifies a minimum number of tasks on one capacity provider, and the `weight`s of each capacity provider determine how tasks are distributed after `base` is satisfied.
1159
+
1160
+
You can associate a default capacity provider strategy with an Amazon ECS cluster. After you do this, a default capacity provider strategy is used when creating a service or running a standalone task in the cluster and whenever a custom capacity provider strategy or a launch type isn't specified. We recommend that you define a default capacity provider strategy for each cluster.
1161
+
1162
+
For more information visit https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-capacity-providers.html
1163
+
1164
+
When the service does not have a capacity provider strategy, the cluster's default capacity provider strategy will be used. Default Capacity Provider Strategy can be added by using the method `addDefaultCapacityProviderStrategy`. A capacity provider strategy cannot contain a mix of EC2 Autoscaling Group capacity providers and Fargate providers.
* Add default capacity provider strategy for this cluster.
269
+
*
270
+
* @param defaultCapacityProviderStrategy cluster default capacity provider strategy. This takes the form of a list of CapacityProviderStrategy objects.
thrownewError('A capacity provider strategy cannot contain a mix of capacity providers using Auto Scaling groups and Fargate providers. Specify one or the other and try again.');
thrownewError(`Capacity provider ${dcp.capacityProvider} must be added to the cluster with addAsgCapacityProvider() before it can be used in a default capacity provider strategy.`);
}).toThrow('Capacity provider test capacityProvider must be added to the cluster with addAsgCapacityProvider() before it can be used in a default capacity provider strategy.');
2244
+
});
2245
+
2246
+
test('should throw an error when capacity providers is length 0 and default capacity provider startegy specified',()=>{
}).toThrow('Capacity provider test capacityProvider must be added to the cluster with addAsgCapacityProvider() before it can be used in a default capacity provider strategy.');
2258
+
});
2259
+
2260
+
test('should throw an error when more than 1 default capacity provider have base specified',()=>{
0 commit comments