Skip to content

Commit

Permalink
Add TaskDef as a property on the construct
Browse files Browse the repository at this point in the history
  • Loading branch information
piradeepk committed Aug 20, 2019
1 parent 04f2e61 commit f8ccdf2
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,27 @@ export interface ApplicationLoadBalancedEc2ServiceProps extends ApplicationLoadB
export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedServiceBase {

/**
* The ECS service in this construct
* The EC2 service in this construct.
*/
public readonly service: Ec2Service;
/**
* The EC2 Task Definition in this construct.
*/
public readonly taskDefinition: Ec2TaskDefinition;

/**
* Constructs a new instance of the ApplicationLoadBalancedEc2Service class.
*/
constructor(scope: Construct, id: string, props: ApplicationLoadBalancedEc2ServiceProps) {
super(scope, id, props);

const taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', {
this.taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', {
executionRole: props.executionRole,
taskRole: props.taskRole
});

const containerName = props.containerName !== undefined ? props.containerName : 'web';
const container = taskDefinition.addContainer(containerName, {
const container = this.taskDefinition.addContainer(containerName, {
image: props.image,
cpu: props.cpu,
memoryLimitMiB: props.memoryLimitMiB,
Expand All @@ -91,7 +95,7 @@ export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedSe
this.service = new Ec2Service(this, "Service", {
cluster: this.cluster,
desiredCount: this.desiredCount,
taskDefinition,
taskDefinition: this.taskDefinition,
assignPublicIp: this.assignPublicIp,
serviceName: props.serviceName,
healthCheckGracePeriod: props.healthCheckGracePeriod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,27 @@ export interface NetworkLoadBalancedEc2ServiceProps extends NetworkLoadBalancedS
export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBase {

/**
* The ECS service in this construct
* The ECS service in this construct.
*/
public readonly service: Ec2Service;
/**
* The EC2 Task Definition in this construct.
*/
public readonly taskDefinition: Ec2TaskDefinition;

/**
* Constructs a new instance of the NetworkLoadBalancedEc2Service class.
*/
constructor(scope: Construct, id: string, props: NetworkLoadBalancedEc2ServiceProps) {
super(scope, id, props);

const taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', {
this.taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', {
executionRole: props.executionRole,
taskRole: props.taskRole
});

const containerName = props.containerName !== undefined ? props.containerName : 'web';
const container = taskDefinition.addContainer(containerName, {
const container = this.taskDefinition.addContainer(containerName, {
image: props.image,
cpu: props.cpu,
memoryLimitMiB: props.memoryLimitMiB,
Expand All @@ -91,7 +95,7 @@ export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBas
this.service = new Ec2Service(this, "Service", {
cluster: this.cluster,
desiredCount: this.desiredCount,
taskDefinition,
taskDefinition: this.taskDefinition,
assignPublicIp: this.assignPublicIp,
serviceName: props.serviceName,
healthCheckGracePeriod: props.healthCheckGracePeriod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ export interface QueueProcessingEc2ServiceProps extends QueueProcessingServiceBa
export class QueueProcessingEc2Service extends QueueProcessingServiceBase {

/**
* The ECS service in this construct
* The EC2 service in this construct.
*/
public readonly service: Ec2Service;
/**
* The EC2 task definition in this construct
*/
public readonly taskDefinition: Ec2TaskDefinition;

/**
* Constructs a new instance of the QueueProcessingEc2Service class.
Expand All @@ -70,8 +74,8 @@ export class QueueProcessingEc2Service extends QueueProcessingServiceBase {
super(scope, id, props);

// Create a Task Definition for the container to start
const taskDefinition = new Ec2TaskDefinition(this, 'QueueProcessingTaskDef');
taskDefinition.addContainer('QueueProcessingContainer', {
this.taskDefinition = new Ec2TaskDefinition(this, 'QueueProcessingTaskDef');
this.taskDefinition.addContainer('QueueProcessingContainer', {
image: props.image,
memoryLimitMiB: props.memoryLimitMiB,
memoryReservationMiB: props.memoryReservationMiB,
Expand All @@ -87,7 +91,7 @@ export class QueueProcessingEc2Service extends QueueProcessingServiceBase {
this.service = new Ec2Service(this, 'QueueProcessingService', {
cluster: this.cluster,
desiredCount: this.desiredCount,
taskDefinition
taskDefinition: this.taskDefinition
});
this.configureAutoscalingForService(this.service);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface ScheduledEc2TaskProps extends ScheduledTaskBaseProps {
export class ScheduledEc2Task extends ScheduledTaskBase {

/**
* The ECS service in this construct
* The EC2 task definition in this construct.
*/
public readonly taskDefinition: Ec2TaskDefinition;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,26 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
* The Fargate service in this construct.
*/
public readonly service: FargateService;
/**
* The Fargate task definition in this construct.
*/
public readonly taskDefinition: FargateTaskDefinition;

/**
* Constructs a new instance of the ApplicationLoadBalancedFargateService class.
*/
constructor(scope: Construct, id: string, props: ApplicationLoadBalancedFargateServiceProps) {
super(scope, id, props);

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

const containerName = props.containerName !== undefined ? props.containerName : 'web';
const container = taskDefinition.addContainer(containerName, {
const container = this.taskDefinition.addContainer(containerName, {
image: props.image,
logging: this.logDriver,
environment: props.environment,
Expand All @@ -87,7 +91,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
this.service = new FargateService(this, "Service", {
cluster: this.cluster,
desiredCount: this.desiredCount,
taskDefinition,
taskDefinition: this.taskDefinition,
assignPublicIp: this.assignPublicIp,
serviceName: props.serviceName,
healthCheckGracePeriod: props.healthCheckGracePeriod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,26 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic
* The Fargate service in this construct.
*/
public readonly service: FargateService;
/**
* The Fargate task definition in this construct.
*/
public readonly taskDefinition: FargateTaskDefinition;

/**
* Constructs a new instance of the NetworkLoadBalancedFargateService class.
*/
constructor(scope: Construct, id: string, props: NetworkLoadBalancedFargateServiceProps) {
super(scope, id, props);

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

const containerName = props.containerName !== undefined ? props.containerName : 'web';
const container = taskDefinition.addContainer(containerName, {
const container = this.taskDefinition.addContainer(containerName, {
image: props.image,
logging: this.logDriver,
environment: props.environment,
Expand All @@ -87,7 +91,7 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic
this.service = new FargateService(this, "Service", {
cluster: this.cluster,
desiredCount: this.desiredCount,
taskDefinition,
taskDefinition: this.taskDefinition,
assignPublicIp: this.assignPublicIp,
serviceName: props.serviceName,
healthCheckGracePeriod: props.healthCheckGracePeriod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ export interface QueueProcessingFargateServiceProps extends QueueProcessingServi
*/
export class QueueProcessingFargateService extends QueueProcessingServiceBase {
/**
* The Fargate service in this construct
* The Fargate service in this construct.
*/
public readonly service: FargateService;
/**
* The Fargate task definition in this construct.
*/
public readonly taskDefinition: FargateTaskDefinition;

/**
* Constructs a new instance of the QueueProcessingFargateService class.
Expand All @@ -60,11 +64,11 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase {
super(scope, id, props);

// Create a Task Definition for the container to start
const taskDefinition = new FargateTaskDefinition(this, 'QueueProcessingTaskDef', {
this.taskDefinition = new FargateTaskDefinition(this, 'QueueProcessingTaskDef', {
memoryLimitMiB: props.memoryLimitMiB || 512,
cpu: props.cpu || 256,
});
taskDefinition.addContainer('QueueProcessingContainer', {
this.taskDefinition.addContainer('QueueProcessingContainer', {
image: props.image,
command: props.command,
environment: this.environment,
Expand All @@ -77,7 +81,7 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase {
this.service = new FargateService(this, 'QueueProcessingFargateService', {
cluster: this.cluster,
desiredCount: this.desiredCount,
taskDefinition
taskDefinition: this.taskDefinition
});
this.configureAutoscalingForService(this.service);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface ScheduledFargateTaskProps extends ScheduledTaskBaseProps {
*/
export class ScheduledFargateTask extends ScheduledTaskBase {
/**
* The ECS service in this construct
* The Fargate task definition in this construct.
*/
public readonly taskDefinition: FargateTaskDefinition;

Expand All @@ -47,8 +47,7 @@ export class ScheduledFargateTask extends ScheduledTaskBase {
constructor(scope: Construct, id: string, props: ScheduledFargateTaskProps) {
super(scope, id, props);

// Create a Task Definition for the container to start, also creates a log driver
this. taskDefinition = new FargateTaskDefinition(this, 'ScheduledTaskDef', {
this.taskDefinition = new FargateTaskDefinition(this, 'ScheduledTaskDef', {
memoryLimitMiB: props.memoryLimitMiB || 512,
cpu: props.cpu || 256,
});
Expand Down

0 comments on commit f8ccdf2

Please sign in to comment.