Skip to content

fix(events-targets): launchType not included for non-AWS_VPC network mode#35989

Open
newlinedeveloper wants to merge 10 commits intoaws:mainfrom
newlinedeveloper:fix/ecs-external-launch-type
Open

fix(events-targets): launchType not included for non-AWS_VPC network mode#35989
newlinedeveloper wants to merge 10 commits intoaws:mainfrom
newlinedeveloper:fix/ecs-external-launch-type

Conversation

@newlinedeveloper
Copy link
Copy Markdown
Contributor

Description

Fixes an issue where the launchType property (including EXTERNAL) was being silently dropped from the CloudFormation template when creating an ECS event target with non-AWS_VPC network modes.

Root Cause

The EcsTask construct only included launchType in the EcsParameters when the task definition used AWS_VPC network mode. For other network modes (like BRIDGE, HOST, NONE), the launchType was omitted entirely from the generated CloudFormation template, causing EventBridge to use default launch type logic instead of the specified launch type.

This was particularly problematic for EXTERNAL launch type, which requires ECS Anywhere infrastructure. When the launch type was dropped, the scheduled task would fail to run because it would try to use EC2 or Fargate launch types instead of EXTERNAL.

Solution

Modified the bind() method in ecs-task.ts to always include launchType in baseEcsParameters, regardless of network mode. The launchType is now included in the CloudFormation template for all network modes, not just AWS_VPC.

Changes:

  • Moved launchType from the conditional AWS_VPC branch into baseEcsParameters
  • Ensures launchType is always included when specified (or computed from task definition compatibility)
  • Network configuration (networkConfiguration) remains only for AWS_VPC network mode, as required by CloudFormation

Testing

  • Added unit test launch type EXTERNAL is included for non-AWS_VPC network mode to verify the fix
  • Added integration test integ.event-external-task.ts to verify the stack synthesizes correctly
  • All existing unit tests continue to pass
  • Verified that LaunchType: 'EXTERNAL' appears in the CloudFormation template for BRIDGE network mode

Related Issue

Fixes #35877

Verification

The fix was verified by:

  1. Running unit tests to ensure LaunchType: 'EXTERNAL' is included in the CloudFormation template
  2. Generating integration test snapshot to verify the stack synthesizes correctly
  3. Confirming that existing tests for EC2 and Fargate launch types continue to pass
  4. The change aligns with AWS CloudFormation documentation which supports LaunchType for all network modes

CloudFormation Template Change

Before:
"EcsParameters": {
"TaskCount": 1,
"TaskDefinitionArn": { "Ref": "TaskDef" }
}
After:
"EcsParameters": {
"TaskCount": 1,
"TaskDefinitionArn": { "Ref": "TaskDef" },
"LaunchType": "EXTERNAL"
}---

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

@aws-cdk-automation aws-cdk-automation requested a review from a team November 8, 2025 13:14
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Nov 8, 2025
@newlinedeveloper newlinedeveloper force-pushed the fix/ecs-external-launch-type branch from 5472f26 to 73c8304 Compare November 8, 2025 13:26
@newlinedeveloper
Copy link
Copy Markdown
Contributor Author

Hi @pahud . This PR needs review and approval. Please check it out. Thanks

@pahud
Copy link
Copy Markdown
Contributor

pahud commented Nov 18, 2025

I just clicked CI approval button to trigger the CI run for this PR. After CI passes you should get pr/pending-community-review label and you are all set. Do not click Update branch after your PR is ready as this triggers another CI build attempt. Thank you.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 11, 2025

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results48 ran48 passed
TestResult
No test annotations available

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 11, 2025

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results with resolved templates48 ran48 passed
TestResult
No test annotations available


// Create a Task Definition with EXTERNAL compatibility
const taskDefinition = new ecs.TaskDefinition(stack, 'TaskDef', {
networkMode: ecs.NetworkMode.BRIDGE, // Non-AWS_VPC network mode
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I want to test all the different NetworkMode with this setup. It can be done easily by encapsulating from line 12 to 32 to into cdk.Construct and add a single input to this construct NetworkMode and iterate over NetworkMode and pass the different values to this construct.

I'm just afraid of in the future a network mode add that doesn't accept external launch type and no one will think of this edge case.

Can you help us doing that?

@gasolima gasolima added the pr/needs-integration-tests-deployment Requires the PR to deploy the integration test snapshots. label Jan 9, 2026
@gasolima gasolima had a problem deploying to deployment-integ-test January 9, 2026 15:51 — with GitHub Actions Error
@gasolima gasolima had a problem deploying to deployment-integ-test January 9, 2026 15:52 — with GitHub Actions Failure
@mergify mergify bot dismissed gasolima’s stale review January 9, 2026 15:52

Pull request has been modified.

@gasolima
Copy link
Copy Markdown
Contributor

@newlinedeveloper the build is failing, let me know if u need help with this

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. effort/medium Medium work item – several days of effort p2 pr/needs-integration-tests-deployment Requires the PR to deploy the integration test snapshots.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(aws_events_targets): Creating an ECS target with launchType EXTERNAL does not work

3 participants