Skip to content

Commit

Permalink
fix(aws-ecs-patterns): Specified taskDefinition was not utilized in q…
Browse files Browse the repository at this point in the history
…ueueProcessingFargateService
  • Loading branch information
badmintoncryer committed Dec 1, 2023
1 parent 71b4648 commit df60287
Show file tree
Hide file tree
Showing 2 changed files with 247 additions and 168 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { Construct } from 'constructs';
import * as ec2 from '../../../aws-ec2';
import { FargateService, FargateTaskDefinition, HealthCheck } from '../../../aws-ecs';
import {
FargateService,
FargateTaskDefinition,
HealthCheck,
} from '../../../aws-ecs';
import { FeatureFlags } from '../../../core';
import * as cxapi from '../../../cx-api';
import { FargateServiceBaseProps } from '../base/fargate-service-base';
import { QueueProcessingServiceBase, QueueProcessingServiceBaseProps } from '../base/queue-processing-service-base';
import {
QueueProcessingServiceBase,
QueueProcessingServiceBaseProps,
} from '../base/queue-processing-service-base';

/**
* The properties for the QueueProcessingFargateService service.
*/
export interface QueueProcessingFargateServiceProps extends QueueProcessingServiceBaseProps, FargateServiceBaseProps {

export interface QueueProcessingFargateServiceProps
extends QueueProcessingServiceBaseProps,
FargateServiceBaseProps {
/**
* Optional name for the container added
*
Expand Down Expand Up @@ -65,16 +73,22 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase {
/**
* Constructs a new instance of the QueueProcessingFargateService class.
*/
constructor(scope: Construct, id: string, props: QueueProcessingFargateServiceProps) {
constructor(
scope: Construct,
id: string,
props: QueueProcessingFargateServiceProps,
) {
super(scope, id, props);

// Create a Task Definition for the container to start
this.taskDefinition = new FargateTaskDefinition(this, 'QueueProcessingTaskDef', {
memoryLimitMiB: props.memoryLimitMiB || 512,
cpu: props.cpu || 256,
family: props.family,
runtimePlatform: props.runtimePlatform,
});
this.taskDefinition =
props.taskDefinition ??
new FargateTaskDefinition(this, 'QueueProcessingTaskDef', {
memoryLimitMiB: props.memoryLimitMiB || 512,
cpu: props.cpu || 256,
family: props.family,
runtimePlatform: props.runtimePlatform,
});

const containerName = props.containerName ?? 'QueueProcessingContainer';

Expand All @@ -88,7 +102,11 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase {
});

// The desiredCount should be removed from the fargate service when the feature flag is removed.
const desiredCount = FeatureFlags.of(this).isEnabled(cxapi.ECS_REMOVE_DEFAULT_DESIRED_COUNT) ? undefined : this.desiredCount;
const desiredCount = FeatureFlags.of(this).isEnabled(
cxapi.ECS_REMOVE_DEFAULT_DESIRED_COUNT,
)
? undefined
: this.desiredCount;

// 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.
Expand Down
Loading

0 comments on commit df60287

Please sign in to comment.