Skip to content

Commit

Permalink
add capacityProviderStrategies props to services
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshizawa56 committed Jun 26, 2022
1 parent 2a3fd5a commit e585d8e
Show file tree
Hide file tree
Showing 30 changed files with 10,004 additions and 3 deletions.
28 changes: 27 additions & 1 deletion packages/@aws-cdk/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,32 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat
});
```

### Set capacityProviderStrategies for ApplicationLoadBalancedFargateService

```ts
declare const cluster: ecs.Cluster;
cluster.enableFargateCapacityProviders();

const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'Service', {
cluster,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
capacityProviderStrategies: [
{
capacityProvider: 'FARGATE_SPOT',
weight: 2,
base: 0,
},
{
capacityProvider: 'FARGATE',
weight: 1,
base: 1,
},
],
});
```

### Add Schedule-Based Auto-Scaling to an ApplicationLoadBalancedFargateService

```ts
Expand Down Expand Up @@ -741,7 +767,7 @@ AWS Fargate. Enable ECS Exec, by setting `enableExecuteCommand` to `true`.

ECS Exec is supported by all Services i.e. `ApplicationLoadBalanced(Fargate|Ec2)Service`, `ApplicationMultipleTargetGroups(Fargate|Ec2)Service`, `NetworkLoadBalanced(Fargate|Ec2)Service`, `NetworkMultipleTargetGroups(Fargate|Ec2)Service`, `QueueProcessing(Fargate|Ec2)Service`. It is not supported for `ScheduledTask`s.

Read more about ECS Exec in the [ECS Developer Guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html).
Read more about ECS Exec in the [ECS Developer Guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html).

Example:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Certificate, CertificateValidation, ICertificate } from '@aws-cdk/aws-c
import { IVpc } from '@aws-cdk/aws-ec2';
import {
AwsLogDriver, BaseService, CloudMapOptions, Cluster, ContainerImage, DeploymentController, DeploymentCircuitBreaker,
ICluster, LogDriver, PropagatedTagSource, Secret,
ICluster, LogDriver, PropagatedTagSource, Secret, CapacityProviderStrategy,
} from '@aws-cdk/aws-ecs';
import {
ApplicationListener, ApplicationLoadBalancer, ApplicationProtocol, ApplicationProtocolVersion, ApplicationTargetGroup,
Expand Down Expand Up @@ -247,6 +247,14 @@ export interface ApplicationLoadBalancedServiceBaseProps {
*/
readonly circuitBreaker?: DeploymentCircuitBreaker;

/**
* A list of Capacity Provider strategies used to place a service.
*
* @default - undefined
*
*/
readonly capacityProviderStrategies?: CapacityProviderStrategy[];

/**
* Name of the load balancer
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IVpc } from '@aws-cdk/aws-ec2';
import {
AwsLogDriver, BaseService, CloudMapOptions, Cluster, ContainerImage, DeploymentController, DeploymentCircuitBreaker,
ICluster, LogDriver, PropagatedTagSource, Secret,
ICluster, LogDriver, PropagatedTagSource, Secret, CapacityProviderStrategy,
} from '@aws-cdk/aws-ecs';
import { INetworkLoadBalancer, NetworkListener, NetworkLoadBalancer, NetworkTargetGroup } from '@aws-cdk/aws-elasticloadbalancingv2';
import { IRole } from '@aws-cdk/aws-iam';
Expand Down Expand Up @@ -183,6 +183,14 @@ export interface NetworkLoadBalancedServiceBaseProps {
*/
readonly circuitBreaker?: DeploymentCircuitBreaker;

/**
* A list of Capacity Provider strategies used to place a service.
*
* @default - undefined
*
*/
readonly capacityProviderStrategies?: CapacityProviderStrategy[];

/**
* Whether ECS Exec should be enabled
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedSe
enableExecuteCommand: props.enableExecuteCommand,
placementConstraints: props.placementConstraints,
placementStrategies: props.placementStrategies,
capacityProviderStrategies: props.capacityProviderStrategies,
});
this.addServiceAsTarget(this.service);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBas
enableExecuteCommand: props.enableExecuteCommand,
placementConstraints: props.placementConstraints,
placementStrategies: props.placementStrategies,
capacityProviderStrategies: props.capacityProviderStrategies,
});
this.addServiceAsTarget(this.service);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
securityGroups: props.securityGroups,
vpcSubnets: props.taskSubnets,
enableExecuteCommand: props.enableExecuteCommand,
capacityProviderStrategies: props.capacityProviderStrategies,
});
this.addServiceAsTarget(this.service);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic
circuitBreaker: props.circuitBreaker,
vpcSubnets: props.taskSubnets,
enableExecuteCommand: props.enableExecuteCommand,
capacityProviderStrategies: props.capacityProviderStrategies,
});
this.addServiceAsTarget(this.service);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "20.0.0",
"files": {
"14bdb67f7676296b9bdb5b121f8aa237cf8df54278388a53a755ffd368499b9b": {
"source": {
"path": "aws-ecs-integ.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "14bdb67f7676296b9bdb5b121f8aa237cf8df54278388a53a755ffd368499b9b.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Loading

0 comments on commit e585d8e

Please sign in to comment.