Skip to content

(aws-ecs): cannot set ephemeralStorageGiB for Windows platform v1.0.0 #37510

@longtv2222

Description

@longtv2222

Describe the bug

I’m encountering an issue when trying to set ephemeralStorageGiB on FargateTaskDefinition while using platformVersion 1.0.0 for FargateService.

cdk synth failed with following error:

«EphemeralStorageGibFeatureRequires» The ephemeralStorageGiB feature requires platform version 1.4.0 or later, got 1.0.0

This validation is correct for Linux container, but it is incorrect for Windows container, where you can set ephemeralStorageGiB Fargate platform version to v1.0

Docs: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-task-storage.html#fargate-task-storage-windows-pv

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Library Version

No response

Expected Behavior

Synth completed successfully

Current Behavior

Image

Reproduction Steps

To reproduce the issue:

import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as cdk from 'aws-cdk-lib/core';
import { Construct } from 'constructs';

export class TestStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const cluster = new ecs.Cluster(this, "Cluster");

    const taskDefinition = new ecs.FargateTaskDefinition(this, "TaskDefinition", {
      runtimePlatform: {
        operatingSystemFamily: ecs.OperatingSystemFamily.WINDOWS_SERVER_2022_CORE,
        cpuArchitecture: ecs.CpuArchitecture.X86_64,
      },
      ephemeralStorageGiB: 40,
      cpu: 1024,
      memoryLimitMiB: 1024,
    });
    taskDefinition.addContainer("Container", {
      image: ecs.ContainerImage.fromRegistry("mcr.microsoft.com/windows/server:ltsc2022"),
    });

    new ecs.FargateService(this, "Service", {
      cluster,
      taskDefinition,
      platformVersion: ecs.FargatePlatformVersion.VERSION1_0,
    });

    /**
     * Workaround for now
     */
    // const cfnTaskDef = taskDefinition.node.defaultChild as ecs.CfnTaskDefinition;
    // cfnTaskDef.addPropertyOverride('EphemeralStorage', {
    //   'SizeInGiB': 40,
    // });
  }
}

Possible Solution

The error was thrown here:

if (props.taskDefinition.ephemeralStorageGiB && isUnsupportedPlatformVersion) {
throw new ValidationError(lit`EphemeralStorageGibFeatureRequires`, `The ephemeralStorageGiB feature requires platform version ${FargatePlatformVersion.VERSION1_4} or later, got ${props.platformVersion}.`, scope);
}

We probably need to:

  1. Make the runtimePlatform property in TaskDefinition public
    private runtimePlatform?: RuntimePlatform;
  2. Use OperatingSystemFamily.isWindows function, and exclude Windows so that the validation error doesn't get triggered anymore
    public isWindows(): boolean {
    return this._operatingSystemFamily?.toLowerCase().startsWith('windows');
    }

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

2.247.0

AWS CDK CLI version

2.1113.0

Node.js Version

v24.11.1

OS

Windows

Language

TypeScript

Language Version

5.9.3

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ecsRelated to Amazon Elastic ContainerbugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions