Skip to content

fix(ecs): task definition rejects runtimePlatform for EC2 compatible tasks - #39331

Open
lazerg wants to merge 1 commit into
aws:mainfrom
lazerg:fix/issue-39330-ecs-runtime-platform
Open

lazerg wants to merge 1 commit into
aws:mainfrom
lazerg:fix/issue-39330-ecs-runtime-platform

Conversation

@lazerg

@lazerg lazerg commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Issue # (if applicable)

Closes #39330.

Reason for this change

TaskDefinition throws CannotSpecifyRuntimePlatform when runtimePlatform is set on a task that is only EC2 compatible. ECS supports runtimePlatform (operatingSystemFamily and cpuArchitecture) for the EC2 launch type too, see the EC2 task definition parameters. So there was no way to pin the CPU architecture or OS family of an EC2 task definition without an escape hatch.

Description of changes

The check now only rejects runtimePlatform for External tasks, and the property is rendered for every other compatibility. The Windows cpu/memory size check is Fargate specific, so it now only runs for Fargate compatible tasks. Without that, an EC2 task with a Windows OS family and no task-level cpu would fail with a Fargate sizing error.

I kept External blocked since I couldn't confirm ECS Anywhere supports it. Nothing that synthesized before changes its output: EC2 tasks with runtimePlatform used to throw.

Describe any new or updated permissions being added

None.

Description of how you validated changes

Added unit tests to task-definition.test.ts for EC2 with a Linux runtime platform, EC2 with a Windows OS family and no task size, and External still throwing. The two EC2 tests fail without the change.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@lazerg
lazerg deployed to automation October 16, 2026 09:23 — with GitHub Actions Active
@lazerg
lazerg deployed to automation October 16, 2026 09:23 — with GitHub Actions Active
@github-actions github-actions Bot added bug This issue is a bug. p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Oct 16, 2026
@lazerg
lazerg deployed to automation October 16, 2026 09:23 — with GitHub Actions Active
@aws-cdk-automation
aws-cdk-automation requested a review from a team October 16, 2026 09:23

@aws-cdk-automation aws-cdk-automation left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

✅ A exemption request has been requested. Please wait for a maintainer's review.

@lazerg

lazerg commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Exemption Request: This fix only removes a synth-time check that blocked runtimePlatform on EC2 tasks. The rendered property is the same one Fargate and Managed Instances tasks already produce. The unit tests in task-definition.test.ts cover the new template output.

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Oct 16, 2026
@maintainer-for-aws

Copy link
Copy Markdown

Automated review

A maintainer will still review this — treat the notes below as a starting point.

📌 Commit acf2cb1

This PR fixes a bug in aws-ecs where ecs.TaskDefinition rejected a runtimePlatform for EC2-compatible tasks even though ECS supports it. It inverts the synth-time validation from an allowlist (Fargate/Managed Instances only) to a blocklist (reject only External tasks), scopes the Fargate-only Windows cpu/memory sizing check to the Fargate path, and removes the launch-type gate on rendering the RuntimePlatform CloudFormation property. The change is small and well-targeted: it only permits previously-rejected EC2 inputs and leaves the synthesized template unchanged for any configuration that already succeeded, so it introduces no breaking change or regression, no new public API surface, and no security exposure. The three added unit tests assert the synthesized template for the EC2 Linux, EC2 Windows (no task size), and still-rejected External cases. One recommended item: the newly-enabled EC2 RuntimePlatform path lacks deploy-backed integration coverage.

🔴 0 blocking · 🟡 1 recommended · ⚪ 0 optional

Files with findings (1)
File Findings
packages/aws-cdk-lib/aws-ecs/lib/base/task-definition.ts 🟡 1

Generated automatically. React 👍 or 👎 to tell us whether this review helped, so we can improve these reviews.

@maintainer-for-aws maintainer-for-aws Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the review summary comment for the overview; the notes below are inline.

Comment on lines 614 to +617
ephemeralStorage: this.ephemeralStorageGiB ? {
sizeInGiB: this.ephemeralStorageGiB,
} : undefined,
runtimePlatform: (this.isFargateCompatible || this.isManagedInstancesCompatible) && this._runtimePlatform ? {
runtimePlatform: this._runtimePlatform ? {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Recommended — This change renders the RuntimePlatform CloudFormation property on EC2 task definitions for the first time (CDK previously rejected it), but the existing ECS integration coverage for RuntimePlatform exercises only the Fargate launch type. Enabling a previously-untested property/launch-type combination normally owes a deploy-backed integration test, since a successful synth alone does not prove ECS accepts RuntimePlatform on an EC2 task definition at register time, and without one a regression or service-side rejection would not be caught (INTEGRATION_TESTS.md#when-are-integration-tests-required). The three new unit tests already assert the synthesized template, so the synthesis behavior is locked in.

Suggested change: Add an EC2 task definition carrying a runtimePlatform to the existing framework-integ/test/aws-ecs/test/fargate/integ.runtime.ts (or a new integ.ec2-runtime-platform.ts under aws-ecs/test/ec2/), deploy it to refresh the snapshot via a real deploy (not --dry-run), and commit the updated *.snapshot/. For example:

new ecs.TaskDefinition(stack, 'Ec2RuntimePlatformTaskDef', {
compatibility: ecs.Compatibility.EC2,
runtimePlatform: {
cpuArchitecture: ecs.CpuArchitecture.ARM64,
operatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
},
// ... a container definition
});

Alternatively, if the unit-level template assertions are judged sufficient for this relaxation, apply the pr-linter/exempt-integ-test label with a short justification.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add an integ test. Refreshing the snapshot needs a real deploy, and I can't run one. ECS documents runtimePlatform for EC2 task definitions (EC2 task definition parameters), and the ARM64 guide lists EC2 as a supported launch type. I asked for an exemption in the PR comments. If a maintainer still wants a deployed integ test, I'll add one.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Oct 16, 2026

This branch was successfully deployed

1 active deployment
automation — acf2cb15 Deployed Oct 16, 2026 by aws-cdk-automation via validate-pr #372852
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(aws_ecs): TaskDefinition rejects runtimePlatform property for non-Fargate tasks

2 participants