Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-ecs-patterns): add service as a property of both ec2 and fargate queue worker services #2780

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sqs = require('@aws-cdk/aws-sqs');
import cdk = require('@aws-cdk/cdk');

/**
* Properties to define a Query Worker service
* Properties to define a queue worker service
*/
export interface QueueWorkerServiceBaseProps {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cdk = require('@aws-cdk/cdk');
import { QueueWorkerServiceBase, QueueWorkerServiceBaseProps } from '../base/queue-worker-service-base';

/**
* Properties to define an Ec2 query worker service
* Properties to define an Ec2 queue worker service
*/
export interface Ec2QueueWorkerServiceProps extends QueueWorkerServiceBaseProps {
/**
Expand Down Expand Up @@ -41,9 +41,15 @@ export interface Ec2QueueWorkerServiceProps extends QueueWorkerServiceBaseProps
}

/**
* Class to create an Ec2 query worker service
* Class to create an Ec2 queue worker service
*/
export class Ec2QueueWorkerService extends QueueWorkerServiceBase {

/**
* The ECS service in this construct
*/
public readonly service: ecs.Ec2Service;

constructor(scope: cdk.Construct, id: string, props: Ec2QueueWorkerServiceProps) {
super(scope, id, props);

Expand All @@ -61,11 +67,11 @@ export class Ec2QueueWorkerService extends QueueWorkerServiceBase {

// Create an ECS service with the previously defined Task Definition and configure
// autoscaling based on cpu utilization and number of messages visible in the SQS queue.
const ecsService = new ecs.Ec2Service(this, 'QueueWorkerService', {
this.service = new ecs.Ec2Service(this, 'QueueWorkerService', {
cluster: props.cluster,
desiredCount: this.desiredCount,
taskDefinition
});
this.configureAutoscalingForService(ecsService);
this.configureAutoscalingForService(this.service);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ export interface FargateQueueWorkerServiceProps extends QueueWorkerServiceBasePr
}

/**
* Class to create a Fargate query worker service
* Class to create a Fargate queue worker service
*/
export class FargateQueueWorkerService extends QueueWorkerServiceBase {
/**
* The Fargate service in this construct
*/
public readonly service: ecs.FargateService;

constructor(scope: cdk.Construct, id: string, props: FargateQueueWorkerServiceProps) {
super(scope, id, props);

Expand All @@ -65,11 +70,11 @@ export class FargateQueueWorkerService extends QueueWorkerServiceBase {

// Create a Fargate service with the previously defined Task Definition and configure
// autoscaling based on cpu utilization and number of messages visible in the SQS queue.
const fargateService = new ecs.FargateService(this, 'FargateQueueWorkerService', {
this.service = new ecs.FargateService(this, 'FargateQueueWorkerService', {
cluster: props.cluster,
desiredCount: this.desiredCount,
taskDefinition
});
this.configureAutoscalingForService(fargateService);
this.configureAutoscalingForService(this.service);
}
}