diff --git a/API.md b/API.md index 21ece2c..c468ec5 100644 --- a/API.md +++ b/API.md @@ -3236,6 +3236,7 @@ const tmApplicationLoadBalancedFargateServiceProps: TmApplicationLoadBalancedFar | customHttpHeaderValue | string | Custom http header value. | | ecsDeploymentHookProps | IIEcsDeploymentHookProps | *No description.* | | efsVolumes | IIefsVolumes[] | *No description.* | +| enableSpotCapacityProvider | boolean | *No description.* | | maxTaskCount | number | The maximum number of task. | | minTaskCount | number | The minumun number od tasks. | | scheduledTaskScheduleExpression | aws-cdk-lib.aws_events.Schedule | *No description.* | @@ -3970,6 +3971,16 @@ public readonly efsVolumes: IIefsVolumes[]; --- +##### `enableSpotCapacityProvider`Optional + +```typescript +public readonly enableSpotCapacityProvider: boolean; +``` + +- *Type:* boolean + +--- + ##### `maxTaskCount`Optional ```typescript diff --git a/src/containers/ecs/ecs-base-pattern.ts b/src/containers/ecs/ecs-base-pattern.ts index ea36852..b043352 100644 --- a/src/containers/ecs/ecs-base-pattern.ts +++ b/src/containers/ecs/ecs-base-pattern.ts @@ -119,6 +119,11 @@ export interface TmApplicationLoadBalancedFargateServiceProps extends ecsPattern * targetMemoryUtilizationPercent */ readonly targetMemoryUtilizationPercent?: number; + + /* + * Enable Spot Capacity Provider + */ + readonly enableSpotCapacityProvider?: boolean; } @@ -163,7 +168,27 @@ export class TmApplicationLoadBalancedFargateService extends ecsPatterns.Applica }, }; - const mergedProps = { ...defautProps, ...props }; + let capacityProviderStrategies; + if (props.enableSpotCapacityProvider) { + capacityProviderStrategies = [ + { + capacityProvider: 'FARGATE', + base: 1, + weight: 0, + }, + { + capacityProvider: 'FARGATE_SPOT', + base: 0, + weight: 1, + }, + ]; + } + + const mergedProps = { + ...defautProps, + ...props, + ...(capacityProviderStrategies && { capacityProviderStrategies }), + }; super(scope, id, mergedProps);