Skip to content

Commit

Permalink
refactor(ecs): normalize memory and cpu props between ec2/fargate (aw…
Browse files Browse the repository at this point in the history
…s#2830)

Normalize all memory and cpu props between ec2 and fargate launch types

BREAKING CHANGES:

* **ecs** Fargate classes take MemoryMiB renamed to MemoryLimitMiB.
* **ecs** Fargate classes take both CPU and MemoryLimitMiB as numbers not strings.
  • Loading branch information
piradeepk authored and ScOut3R committed Jun 13, 2019
1 parent 4b7af87 commit c5001e7
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const loadBalancedEcsService = new ecsPatterns.LoadBalancedEc2Service(stack, 'Se
```ts
const loadBalancedFargateService = new ecsPatterns.LoadBalancedFargateService(stack, 'Service', {
cluster,
memoryMiB: '1GB',
cpu: '512',
memoryLimitMiB: 1024,
cpu: 512,
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
});
```
Expand Down Expand Up @@ -76,7 +76,7 @@ const queueProcessingEc2Service = new QueueProcessingEc2Service(stack, 'Service'
```ts
const queueProcessingFargateService = new QueueProcessingFargateService(stack, 'Service', {
cluster,
memoryMiB: '512',
memoryLimitMiB: 512,
image: ecs.ContainerImage.fromRegistry('test'),
command: ["-c", "4", "amazon.com"],
enableLogging: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface LoadBalancedFargateServiceProps extends LoadBalancedServiceBase
*
* @default 256
*/
readonly cpu?: string;
readonly cpu?: number;

/**
* The amount (in MiB) of memory used by the task.
Expand All @@ -41,7 +41,7 @@ export interface LoadBalancedFargateServiceProps extends LoadBalancedServiceBase
*
* @default 512
*/
readonly memoryMiB?: string;
readonly memoryLimitMiB?: number;
}

/**
Expand All @@ -58,7 +58,7 @@ export class LoadBalancedFargateService extends LoadBalancedServiceBase {
super(scope, id, props);

const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', {
memoryMiB: props.memoryMiB,
memoryLimitMiB: props.memoryLimitMiB,
cpu: props.cpu
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface QueueProcessingFargateServiceProps extends QueueProcessingServi
*
* @default 256
*/
readonly cpu?: string;
readonly cpu?: number;

/**
* The amount (in MiB) of memory used by the task.
Expand All @@ -41,7 +41,7 @@ export interface QueueProcessingFargateServiceProps extends QueueProcessingServi
*
* @default 512
*/
readonly memoryMiB?: string;
readonly memoryLimitMiB?: number;
}

/**
Expand All @@ -58,8 +58,8 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase {

// Create a Task Definition for the container to start
const taskDefinition = new ecs.FargateTaskDefinition(this, 'QueueProcessingTaskDef', {
memoryMiB: props.memoryMiB !== undefined ? props.memoryMiB : '512',
cpu: props.cpu !== undefined ? props.cpu : '256',
memoryLimitMiB: props.memoryLimitMiB,
cpu: props.cpu,
});
taskDefinition.addContainer('QueueProcessingContainer', {
image: props.image,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@
]
},
"Family": "awsecsintegL3TaskDefAA25240E",
"Memory": "1GB",
"Memory": "1024",
"NetworkMode": "awsvpc",
"RequiresCompatibilities": [
"FARGATE"
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const cluster = new ecs.Cluster(stack, 'FargateCluster', { vpc });

new ecsPatterns.LoadBalancedFargateService(stack, 'L3', {
cluster,
memoryMiB: '1GB',
cpu: '512',
memoryLimitMiB: 1024,
cpu: 512,
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export = {
// WHEN
new ecsPatterns.QueueProcessingFargateService(stack, 'Service', {
cluster,
memoryMiB: '512',
memoryLimitMiB: 512,
image: ecs.ContainerImage.fromRegistry('test')
});

Expand Down Expand Up @@ -74,7 +74,7 @@ export = {
// WHEN
new ecsPatterns.QueueProcessingFargateService(stack, 'Service', {
cluster,
memoryMiB: '512',
memoryLimitMiB: 512,
image: ecs.ContainerImage.fromRegistry('test'),
command: ["-c", "4", "amazon.com"],
enableLogging: false,
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ To run a task or service with Amazon EC2 launch type, use the `Ec2TaskDefinition
`FargateTaskDefinition`. These classes provide a simplified API that only contain
properties relevant for that specific launch type.

For a `FargateTaskDefinition`, specify the task size (`memoryMiB` and `cpu`):
For a `FargateTaskDefinition`, specify the task size (`memoryLimitMiB` and `cpu`):

```ts
const fargateTaskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', {
memoryMiB: '512',
cpu: '256'
memoryLimitMiB: 512,
cpu: 256
});
```
To add containers to a task definition, call `addContainer()`:
Expand Down Expand Up @@ -186,7 +186,7 @@ The following example uses both:
```ts
const taskDefinition = new ecs.TaskDefinition(this, 'TaskDef', {
memoryMiB: '512',
cpu: 256,
cpu: '256',
networkMode: 'awsvpc',
compatibility: ecs.Compatibility.Ec2AndFargate,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface FargateTaskDefinitionProps extends CommonTaskDefinitionProps {
*
* @default 256
*/
readonly cpu?: string;
readonly cpu?: number;

/**
* The amount (in MiB) of memory used by the task.
Expand All @@ -36,7 +36,7 @@ export interface FargateTaskDefinitionProps extends CommonTaskDefinitionProps {
*
* @default 512
*/
readonly memoryMiB?: string;
readonly memoryLimitMiB?: number;
}

export interface IFargateTaskDefinition extends ITaskDefinition {
Expand Down Expand Up @@ -71,8 +71,8 @@ export class FargateTaskDefinition extends TaskDefinition implements IFargateTas
constructor(scope: Construct, id: string, props: FargateTaskDefinitionProps = {}) {
super(scope, id, {
...props,
cpu: props.cpu || '256',
memoryMiB: props.memoryMiB || '512',
cpu: props.cpu !== undefined ? String(props.cpu) : '256',
memoryMiB: props.memoryLimitMiB !== undefined ? String(props.memoryLimitMiB) : '512',
compatibility: Compatibility.Fargate,
networkMode: NetworkMode.AwsVpc,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@
],
"Cpu": "512",
"Family": "awsecsintegTaskDef6FDFB69A",
"Memory": "1GB",
"Memory": "1024",
"NetworkMode": "awsvpc",
"RequiresCompatibilities": [
"FARGATE"
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-ecs/test/fargate/integ.lb-awsvpc-nw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const vpc = new ec2.Vpc(stack, 'Vpc', { maxAZs: 2 });
const cluster = new ecs.Cluster(stack, 'FargateCluster', { vpc });

const taskDefinition = new ecs.FargateTaskDefinition(stack, 'TaskDef', {
memoryMiB: '1GB',
cpu: '512'
memoryLimitMiB: 1024,
cpu: 512
});

const container = taskDefinition.addContainer('web', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const cluster = new ecs.Cluster(stack, 'FargateCluster', { vpc });

// Build task definition
const taskDefinition = new ecs.FargateTaskDefinition(stack, 'TaskDef', {
memoryMiB: '512',
cpu: '256'
memoryLimitMiB: 512,
cpu: 256
});
taskDefinition.addContainer('TheContainer', {
image: ecs.ContainerImage.fromAsset(stack, 'EventImage', { directory: path.resolve(__dirname, 'eventhandler-image') }),
Expand Down

0 comments on commit c5001e7

Please sign in to comment.